mvc3 jquery类选择器不工作
我对Jquery和MVC3有一个问题,我很确定这与模型绑定有关,我基本上是在尝试使用Jquery将dropdownlist加载到我的页面,现在下面的示例可以运行了mvc3 jquery类选择器不工作,jquery,asp.net-mvc-3,model,Jquery,Asp.net Mvc 3,Model,我对Jquery和MVC3有一个问题,我很确定这与模型绑定有关,我基本上是在尝试使用Jquery将dropdownlist加载到我的页面,现在下面的示例可以运行了 @model way.Models.servicer @Html.DropDownListFor(model => model.adtype, new SelectList( new List<Object>{ new { Text =
@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
@DropDownListFor(model=>model.adtype,新选择列表(
新列表{
新的{Text=”“,Value=”“},
新的{Text=“Financial”,Value=“Financial”},“Value”,“Text”),新的{@class=“mylist”})
$(“.mylist”).change(函数(){
如果($(this.val()=“财务”){
$(“#miness”).load('/Listings/service.credit');
}
});
然后加载这个dropdownlist,模型服务程序
@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.servicer
@DropDownListFor(model=>model.keyword,新选择列表(
新列表{
新的{Text=“簿记”,Value=“簿记”},
新的{Text=“Credit Repair”,Value=“Credit Repair”},“Value”,“Text”),新的{@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\u详细信息
@DropDownListFor(model=>model.profile.groups,新选择列表(
新列表{
新的{Text=”“,Value=”“},
新的{Text=“Computer”,Value=“Computer”},“Value”,“Text”),新的{@class=“bty”})
$(“.bty”).change(函数(){
if($(this.val()=“计算机”){
$(“#miness”).load('/Listings/ding.computer');
}
});
然后假设加载这个dropdownlist
@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" })
@model way.Models.article\u详细信息
@DropDownListFor(model=>model.profile.role,新选择列表(新列表{
新的{Text=“windows”,Value=“windows”},新的{Text=“mac”,Value=“mac”},“Value”,“Text”),新的{@class=“computer”})
我不明白为什么一个有效而另一个无效。有一个小的区别第二个示例在一个视图中有两个模型,因此model.profile.role可能在某种程度上,一个视图中的两个模型有问题,但我正在引用类,所以我不知道发生了什么事。有什么建议吗?您是否通过jquery ajax加载下拉列表如果是,那么您必须重新绑定jquery事件,因为只有在jquery之前加载dom元素时,jquery绑定才起作用