MVC4中具有模型绑定的两个@ Html.DropDownListFor的级联更新 [英] Cascading update of two @Html.DropDownListFor in MVC4 with model binding
问题描述
I saw this, however I have a different Q. I have a view like this:
@model myPrj.Models.RollCallModel
...
<table>
<tr> //Master DDL
<td>
@Html.LabelFor(model => model.CourseID)
@Html.DropDownListFor(model => model.CourseID,
new SelectList(new myPrj.Models.myDbContext().Courses
.Where(c => c.StatusID == 0), "ID", "ID"),
"choose...", new { id = "ddlCourse"})
@Html.ValidationMessageFor(model => model.CourseID)
</td>
</tr>
<tr> //Detail DDL
<td>
@Html.LabelFor(model => model.PersonnelID)
@Html.DropDownListFor(model => model.PersonnelID,
null, "choose another...", new { id = "ddlPersonnel"})
@Html.ValidationMessageFor(model => model.PersonnelID)
</td>
</tr>
</table>
...
我对使用jquery级联更新了解得足够多.我的问题是,是否有可能对这些DDL执行级联更新,而无需为Detail DDL编写<option>something</option>
的迭代?如果没有,最方便的选择是什么?
I know enough about cascading updates with jquery. My Q is that is it possible to perform a cascade update to these DDLs without needing to write an iteration of <option>something</option>
for the Detail DDL? If no, what's the handiest alternative?
注意:实际上,由于模型绑定的约定,实际上我正在尝试使用html helper渲染详细DDL.如果我别无选择,只能用<select id=""></select>
进行渲染,该如何将select
元素绑定到模型上?
note: In fact I'm trying to render the detail DDL with html helper because of the convention of model binding. If I have no choice but to render it by <select id=""></select>
, how can I bind this select
element to the model?
感谢
更新:似乎没有办法...(仍在等待,甚至正在搜索...)
Update: It seems that there's no way... (still waiting and indeed searching...)
推荐答案
是的!当然有:详情请参阅一个>.但是,它需要每个附加DDL的其他操作方法和局部视图.
Yeah! of course there is: See this for details. However it needs an additional action method and a partial view for each Detail DDL.
最后我想决定通过JQuery并在JsonResult上迭代地添加<options>
...
finally I like to decide to go through JQuery and iterationally adding <options>
over the JsonResult...
这篇关于MVC4中具有模型绑定的两个@ Html.DropDownListFor的级联更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!