html.dropdownlist中的问题(如何绑定选定的值) [英] problem in html.dropdownlist (how to bind with selected value)
本文介绍了html.dropdownlist中的问题(如何绑定选定的值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这里您可以看到我的操作方法,我正在尝试创建具有选定值的选择列表
我该怎么办?
here you can see my action mehod,i am trying to create selectlist with selected value
how can i do?
public ActionResult Create()
{
IEnumerable<DoctorType> DocType = from v in context.DoctorTypes select v;
ViewData["DoctypeData"] = new SelectList(DocType, "ncode", "cDoctorName");
return View();
}
这是我的dropdowncode
This is my dropdowncode
<label class="custom-select"> <%: Html.DropDownList("DocType", ViewData["DoctypeData"] as SelectList)%></label>
请使用选定值
pls helpme for bind dropdown with selected value
推荐答案
@ Html.DropDownListFor(m => m.categories.CategoryID,Model.categories.
. CategoryList,-选择一个-")
@Html.DropDownListFor(m=>m.categories.CategoryID,Model.categories.
CategoryList,"--Select one--")
var list = new [] {
新人员{ID = 1,名称=名称1"},
新人员{ID = 2,Name ="Name2"},
新人员{ID = 3,名称=名称3"}
};
var selectList = new SelectList(list,"Id","Name",2);
ViewData ["People"] = selectList;
Html.DropDownList("PeopleClass",(SelectList)ViewData ["People"])
var list = new[] {
new Person { Id = 1, Name = "Name1" },
new Person { Id = 2, Name = "Name2" },
new Person { Id = 3, Name = "Name3" }
};
var selectList = new SelectList(list, "Id", "Name", 2);
ViewData["People"] = selectList;
Html.DropDownList("PeopleClass", (SelectList)ViewData["People"])
这篇关于html.dropdownlist中的问题(如何绑定选定的值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文