2016-10-20 34 views
-2

如何将IEnumerable模型绑定到DropDownListFor和DropDownList @model IEnumerable @ Html.DropDownListFor();ASP.NET MVC DropDownListFor与Ienumerable类型的模型<model>

+0

有一个视图模型,它有一个属性用于收集,一个用于保存选定的值。 [Here](http://stackoverflow.com/questions/39550804/what-is-the-best-ways-to-bind-html-dropdownlistfor-in-asp-net-mvc5)是一些示例代码 – Shyju

+0

然后告诉我我怎么能得到 – SamSanju

+0

看到我发表在prev评论的链接。 – Shyju

回答

0
View 
@Html.DropDownListFor(x => x.doc_typeid, Model.doctype_name, "--Select--", new { @class = "form-control", @style="width:auto;" }) 
Controller 
var docTypes = from c in db.tm_doc_type select c; 
doctype_name = new SelectList(docTypes, "doc_typeid", "doctype_name"), 
相关问题