jquery multiSelect不使用razor与MVC一起工作
我尝试使用multiselect来显示允许使用该库进行多次选择的下拉选择。我成功地实现了不使用母版页。 但当我使用母版页代码时,会出现错误。(“不支持方法”)。 我正在粘贴不使用母版页的简单代码,请任何人帮助我如何使用MVC中使用母版页的jquery库 这里是风景jquery multiSelect不使用razor与MVC一起工作,jquery,asp.net-mvc-3,jquery-ui,razor,Jquery,Asp.net Mvc 3,Jquery Ui,Razor,我尝试使用multiselect来显示允许使用该库进行多次选择的下拉选择。我成功地实现了不使用母版页。 但当我使用母版页代码时,会出现错误。(“不支持方法”)。 我正在粘贴不使用母版页的简单代码,请任何人帮助我如何使用MVC中使用母版页的jquery库 这里是风景 @{ Layout = null; } @using LST.EMOTS.DynamicForms.Web.Models <!DOCTYPE html> <html> <head> <titl
@{
Layout = null;
}
@using LST.EMOTS.DynamicForms.Web.Models
<!DOCTYPE html>
<html>
<head>
<title>Index1</title>
<script src="@Url.Content("~/Scripts/jquery-1.4.4.js")" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.widget.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.multiSelect.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.bgiframe.min.js" type="text/javascript"></script>
<link href="../../Content/jquery.multiSelect.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function () {
$("#control_3").multiSelect();
});
function change1() {
alert('this is called first');
$('#hfHiddenfield').val($("#control_3").selectedValuesString());
alert($('#hfHiddenfield').val());
}
</script>
</head>
<body>
<div>
@using (Html.BeginForm())
{
<select id="control_3" name="control_3[]" multiple="multiple" class="multiSelect" >
<option value=""></option>
@foreach ( Item itm in ViewBag.objectData )
{
<option value="@itm.Id" >@itm.Name</option>
}
</select>
<input type="hidden" value="" name="crtrlValues" id ="hfHiddenfield" />
<input type="submit" value="GO" onclick="change1()" />
}
</div>
</body>
</html>
这是模型
public class MyModel
{
public IEnumerable<int> SelectedItemIds { get; set; }
public IEnumerable<Item> AvailableItems
{
get
{
return new[]
{
new Item { Id = 1, Name = "Item 1" , isSeleced=false },
new Item { Id = 2, Name = "Item 2" ,isSeleced=true},
new Item { Id = 3, Name = "Item 3",isSeleced=false }
};
}
}
}
public class Item
{
public int Id { get; set; }
public string Name { get; set; }
public bool isSeleced { get; set; }
}
公共类MyModel
{
公共IEnumerable SelectedItemId{get;set;}
公共IEnumerableItems
{
得到
{
返回新的[]
{
新项目{Id=1,Name=“项目1”,isSeleced=false},
新项目{Id=2,Name=“项目2”,isSeleced=true},
新项目{Id=3,Name=“项目3”,isSeleced=false}
};
}
}
}
公共类项目
{
公共int Id{get;set;}
公共字符串名称{get;set;}
公共布尔被删除{get;set;}
}
这是一个完美的解决方案,但这与我们的母版页。
请提供我如何使用母版页的解决方案。我怀疑问题在于没有使用
@Url.Content(..)
获取其余js文件的路径。您将它用于jQuery js,为什么不用于其他js文件
尝试对所有js文件使用
@Url.Content(..)
,希望它能解决您的问题。既然您使用MVC,请尽量避免使用相对路径,请始终使用@Url.Content(..)
来获取资源的路径。我也这样做了。任何一个plz都会为我提供解决方案,为什么使用母版页都不起作用。假设使用了@url.Content…..当您使用母版页时,您是否看到select元素id被更改?它仍然是控制3吗?是否可以签入视图源?出现.multiSelect()的问题;这是选择列表的事件。如果即使在使用类选择器之后,在使用母版页时它也不起作用,那么我确信js文件路径是混乱的。他们没有在页面上下载,因此正在为multiselect
插件获取方法不受支持“
错误。
public class MyModel
{
public IEnumerable<int> SelectedItemIds { get; set; }
public IEnumerable<Item> AvailableItems
{
get
{
return new[]
{
new Item { Id = 1, Name = "Item 1" , isSeleced=false },
new Item { Id = 2, Name = "Item 2" ,isSeleced=true},
new Item { Id = 3, Name = "Item 3",isSeleced=false }
};
}
}
}
public class Item
{
public int Id { get; set; }
public string Name { get; set; }
public bool isSeleced { get; set; }
}