Asp.net MVC 2 级联下拉
嗨,这是我的控制器代码:
public ActionResult Create()
{
makelist = new SelectList(db.CountryMasters.ToList(), "CountryID", "CountryName",1);
ViewData["CounrtyMaster"] = makelist;
var modelList = new CascadingSelectList(clientMasterManagement.GetState(makelist.SelectedValue.ToString()), "StateID", "StateName");
ViewData["StateMaster"] = modelList;
return View("Create");
}
这是我的视图代码:
<div class="editor-field">
<%= Html.DropDownList("CountryID", ViewData["CounrtyMaster"] as SelectList)%>
<%= Html.ValidationMessageFor(model => model.CountryID) %>
</div>
<%= Html.CascadingDropDownList("StateMaster","CountryMaster")%>
当我选择上面的列表时,它不会影响第二个列表,任何人都可以在这里帮助我吗???
Hi, this is my Controller Code:
public ActionResult Create()
{
makelist = new SelectList(db.CountryMasters.ToList(), "CountryID", "CountryName",1);
ViewData["CounrtyMaster"] = makelist;
var modelList = new CascadingSelectList(clientMasterManagement.GetState(makelist.SelectedValue.ToString()), "StateID", "StateName");
ViewData["StateMaster"] = modelList;
return View("Create");
}
and this is my View Code:
<div class="editor-field">
<%= Html.DropDownList("CountryID", ViewData["CounrtyMaster"] as SelectList)%>
<%= Html.ValidationMessageFor(model => model.CountryID) %>
</div>
<%= Html.CascadingDropDownList("StateMaster","CountryMaster")%>
when I select upper list it's not affecting the second one, can anyone help me here???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在控制器操作中使用
CascadingSelectList
函数而不是SelectList
User
CascadingSelectList
function instead ofSelectList
in your controller actionHtml.CascadingDropDownList 不是标准的 MVC 帮助器。我认为您正在使用 斯蒂芬·瓦尔特的助手。如果是这样,这个问题将帮助您:
ASP.NET MVC - Cascading Drop Down
Html.CascadingDropDownList is not a standard MVC helper. I take it that you are using Stephen Walther's helper. If so this question will help you out:
ASP.NET MVC - Cascading Drop Down