我有一个带有表格和JQuery tablesorter插件的视图。它运行得非常好。但是,当我尝试将表格和tablesorter插件插入到PartialView中,并通过Ajax将此PartialView插入到View页面中时,tablesorter无法工作。
在Partial View中,jQuery不起作用。插件没有被调用。
我的控制器代码:
在Partial View中,jQuery不起作用。插件没有被调用。
我的控制器代码:
public ActionResult MyTable()
{
//query type IQueryable
return PartialView(query);
}
我的基本视图代码
...
<% using (Ajax.BeginForm("MyOrgsTable", new AjaxOptions { UpdateTargetId="MyTable", InsertionMode = InsertionMode.Replace}))
{ %> <p>
Name: <%=Html.TextBox("search_org", ViewData["searchName"])%> <input type="submit" value="Поиск" />
</p>
<% } %>
<div id="MyTable">
</div>
...
我的部分视图代码:
<script type="text/javascript" id="js">
$(document).ready(function() {
// call the tablesorter plugin
$("table").tablesorter({
headers: {
5: { sorter: "MyDate" },
6: { sorter: "MyDate" }
},
widthFixed: true,
widgets: ['zebra']
});
});
</script>
<table cellspacing="1" class="tablesorter">
<thead>
<tr>
...
</tr>
</thead>
<tbody>
<% foreach ( var item in Model )
{ %>
// some table rows
<% } %>
</tbody>
</table>
我的主页面标题:
<script type="text/javascript" src="<%= Url.Content("~/Scripts/MicrosoftAjax.js") %>"></script>
<script type="text/javascript" src="<%= Url.Content("~/Scripts/MicrosoftMvcAjax.js") %>"></script>
<script type="text/javascript" src="<%= Url.Content("~/Scripts/jquery-1.3.2.js") %>"></script>
<script type="text/javascript" src="<%= Url.Content("~/Scripts/jquery.tablesorter.js") %>"></script>
<script type="text/javascript" src="<%= Url.Content("~/Scripts/jquery.tablesorter.pager.js") %>"></script>