MVC的多选下拉列表中选择

MVC的多选下拉列表中选择

本文介绍了Razor mutliselect下拉设置值,在ASP.NET MVC的多选下拉列表中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我需要一种方法在Web应用程序的编辑视图中的多选下拉列表中设置已选择的值(ASP.NET,Mvc) 来自视图代码,我将选定的ID传递给选定的值数组。(当我从DB返回值时,将这些值分配给数组然后分配到这里。 我需要一个通过设置选择已选择的值来编辑视图。 请有人建议这样做 谢谢。 我尝试了什么:I need a way to set already selected values in a multi select dropdown in a edit view in a web application (ASP.NET, Mvc)from view code,I passed selected ids in to selected values array.(when I return values from DB , assign those in to a array then assign to here.I need a edit view by set selecting already selected values.please anyone suggest way to do thisThank you.What I have tried://View <div class="form-group"> <label>Choose Categories</label> @Html.DropDownListFor(model => model.SelectedValues, new MultiSelectList(Models.GetCategoryList().OrderBy(c => c.Value), "Key", "Value"), "Select Category", new { @class = "chzn-select form-control", multiple = "multiple" }) </div>//Modelpublic int[] SelectedValues { get; set; }//Controller public ActionResult Edit(int id) { return View(GetDetails(id)); } 在GetDetails(id)中从DB获取值,并返回一个模型对象In GetDetails(id) take values from DB , and return a model objectpublic GetDetails(){ int[] arr = new int[2]; arr[0] = 4; arr[1] = 5; modelObj.SelectedValues = arr;.............return modelObj;}推荐答案@Html.ListBoxFor(model => model.SelectedValues, new MultiSelectList(Models.GetCategoryList().OrderBy(c => c.Value), "Key", "Value", Model.SelectedValues), "Select Category", new { @class = "chzn-select form-control", multiple = "multiple" }) ASP.NET MVC DropDownLists - 多项选择a和枚举支持 [ ^ ] 这篇关于Razor mutliselect下拉设置值,在ASP.NET MVC的多选下拉列表中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-13 14:12