Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 从视图中的多个列表框中检索选择_Jquery_Asp.net Mvc - Fatal编程技术网

Jquery 从视图中的多个列表框中检索选择

Jquery 从视图中的多个列表框中检索选择,jquery,asp.net-mvc,Jquery,Asp.net Mvc,我的视图中有一个编辑器模板,它有一个名为服务类型的模型属性。简言之,页面上呈现的列表框数量不可能超过N个 @Html.ListBoxFor(model => model.ServiceTypes, new MultiSelectList(RunLog.Domain.Lists.GlobalList.PartsServiceTypes(), "ID", "Name"), new { style = "width: 200px; height: 80px;", id = "lstbox", n

我的视图中有一个编辑器模板,它有一个名为服务类型的模型属性。简言之,页面上呈现的列表框数量不可能超过N个

@Html.ListBoxFor(model => model.ServiceTypes, new MultiSelectList(RunLog.Domain.Lists.GlobalList.PartsServiceTypes(), "ID", "Name"), new { style = "width: 200px; height: 80px;", id = "lstbox", name = "listbox" } )
下面的Jquery.Load函数呈现局部视图。在此对话框中有一个带有复选框的树视图,一旦它们从树视图中选择/选中项目并点击选择,例如,它们选择10个复选框,点击选择10后,将显示列表vboxes。有一个jquery.load,它从操作中获取信息并呈现列表框

if (btnText == 'Select') {
                partTextArea = "";
                $("#parts :checkbox:checked").each(function () {

                    var v = $(this).val();
                    if (partTextArea.length > 0) {
                        partTextArea = partTextArea + "| ";

                    }
                    partTextArea = partTextArea + v;
                });

                $('body').css('cursor', 'wait');
                $("#inputParts").load(serviceListPartsUrl, { ServiceEntryID: $("#ServiceEntryID").val(), Parts: partTextArea });

                $('body').css('cursor', 'auto');
            }

现在的问题是,每次发生this.load之后,多个列表框中先前选择的服务类型都会丢失。有什么想法吗?

听起来好像每次调用load时都要替换所有的列表框,它们都在$'inputParts'中吗?是的,@BassamMehanni说了什么。一种可能的方法是安排每个列表框都有一个唯一的id,并且这些相同的id再次出现在重新提供的部分中,然后您可以让jQuery/javascript记住列表框的值。在成功处理程序中加载并重置它们。听起来不错,我应该如何结束这个问题,因为我现在知道了要遵循的方法。