简体   繁体   English

在ASP.NET MVC中的复选框checkevent上加载视图

[英]load view on checkbox checkevent in ASP.NET MVC

In an ASP.NET MVC View , I have checkbox control 在ASP.NET MVC视图中,我具有复选框控件

@Html.CheckBoxFor(
    model => model.ServiceListDetails.IsCargoLiquidCall, 
    new { id = "chkCargoLiquid"}
) Cargo Call (Liquid)

 @Html.CheckBoxFor(
    model => model.ServiceListDetails.IsCargoDryCall, 
    new { id = "chkCargoDry"}
) Cargo Call (Dry)

..... and five more checkboxes. .....和另外五个复选框。 On checkbox checked event of each checkbox, i need to 'RenderAction' to fieldset, below 在每个复选框的复选框选中事件上,我需要“ RenderAction”到下面的字段集

<fieldset>
@{Html.RenderAction("_CargoCalLiquid", "Services");}
</fieldset>

<fieldset>
 @{Html.RenderAction("_CargoCalDry", "Services");}
</fieldset>

This is happening on load of view, but the same is taking lot of time to load as there are seven checkboxes for every type and respective list of services. 这是在加载视图时发生的,但是加载同样花费很多时间,因为每种类型和相应的服务列表都有七个复选框。

So, when click of the checkbox, only then it should load.. How can this be achieved? 因此,当单击复选框时,才应加载该复选框。如何实现?

I tried the below, but not working.. I am new to MVC, or is there any way to load the same to datagrid control do that it will take less time.. 我尝试了下面的方法,但是没有用..我是MVC的新手,或者有什么方法可以将其加载到datagrid控制中,这将花费更少的时间。

Please appreciating help.. 请感谢帮助。

use javascript/jquery events and ajax call 使用javascript / jquery事件和ajax调用

Some thing like below 像下面这样

 @Html.CheckBoxFor(
        model => model.ServiceListDetails.IsCargoLiquidCall, 
        new { id = "chkCargoLiquid",onchange="RenderService()"}
    )
    <div id="TargetID"><div/>

    <script>
    function RenderService(){
           $.ajax({
                 type: "POST",
                 url: '@Url.Content("~/Services/_CargoCalLiquid")',
                 success: function(result) {
                    $('#TargetID').html(html);

                 },
                 error: function(msg) {
                     alert("failed");
                 }
             });
    }
    <script/>

hope this may help you 希望这对您有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM