我对Jquery和MVC3有一个问题--我很确定它与模型绑定有关,我基本上是试图使用jquery 将下拉列表加载到我的页面,下面的示例是works.
@model way.Models.servicer
@Html.DropDownListFor(model => model.adtype, new SelectList(
new List<Object>{
new { Text = " ", Value = " "},
new { Text = "Financial", Value = "Financial"}}, "Value", "Text"), new {@class="mylist" })
<script>
$(".mylist").change(function () {
if ($(this).val() == "Financial") {
$("#miness").load('/Listings/service .credit');
}
});
</script>然后加载这个下拉列表,模型服务程序是
@model way.Models.servicer
@Html.DropDownListFor(model => model.keyword, new SelectList(
new List<Object>{
new { Text = "Book-keeping", Value = "Book-keeping"},
new { Text = "Credit Repair", Value = "Credit Repair"}}, "Value", "Text"), new {@class="credit" }) 上面的例子现在起作用了,我基本上使用了下面这个模型的相同步骤,但是这个示例不工作
@model way.Models.article_detail
@Html.DropDownListFor(model => model.profile.groups, new SelectList(
new List<Object>{
new { Text = " ", Value = " "},
new { Text = "Computer", Value = "Computer"}}, "Value", "Text"), new {@class="bty"})
<script>
$(".bty").change(function () {
if ($(this).val() == "Computer") {
$("#miness").load('/Listings/ding .computer');
}
});
</script>,然后假设加载这个下拉列表。
@model way.Models.article_detail
@Html.DropDownListFor(model => model.profile.role, new SelectList(new List<Object>{
new { Text = "windows", Value = "windows"},new { Text = "mac", Value = "mac"}}, "Value", "Text"), new { @class = "computer" })我不明白为什么1起作用,另一起不起作用。有一个小的区别,第二个例子在一个视图中有两个模型,因此,model.profile.role,可能是以某种方式,在一个视图中的两个模型正在抛出东西,但是我是在引用类,所以我不知道发生了什么,有什么建议吗?
发布于 2013-09-22 05:48:35
您是否通过jquery加载下拉列表,如果是,则必须将jquery事件重新绑定到控件,因为jquery绑定只有在jquery之前加载dom元素时才能工作。
https://stackoverflow.com/questions/18937720
复制相似问题