JavaScript代码在第一次加载页面时不会工作,但是当我进行一些分页时,它会工作得很好
我的sp.net mvc web应用程序中有以下索引视图:-JavaScript代码在第一次加载页面时不会工作,但是当我进行一些分页时,它会工作得很好,javascript,jquery,html,asp.net-mvc,razor,Javascript,Jquery,Html,Asp.net Mvc,Razor,我的sp.net mvc web应用程序中有以下索引视图:- @model IPagedList<TMS.Models.VirtualMachine> @{ ViewBag.Title = "Virtual Machine List"; } <h2>Virtual Machine List</h2> <i class=" icon-plus"></i>@Html.ActionLink("Create New", "Creat
@model IPagedList<TMS.Models.VirtualMachine>
@{
ViewBag.Title = "Virtual Machine List";
}
<h2>Virtual Machine List</h2>
<i class=" icon-plus"></i>@Html.ActionLink("Create New", "Create") | @Html.ActionLink("Assets","Asset")
//code goes here
@Html.Partial("**_PagedVMTable**",Model)
现在我面临以下问题:-
谢谢哪个部分没有执行?何时创建“服务器排序”和“机架排序”?可能从.click调用切换到$(“#ServerSort”).live(“click”,function(){});你能显示你的按钮是在哪里定义的吗?你能在多个浏览器中重现这个问题吗?(Chrome,IE,FF,Safari)@b是的,这些按钮是在另一个局部视图中定义的,该视图使用以下@Html.partial(“~/Views/VirtualMAchine/_VMTable.cshtml”,Model)在_pagedvmtablepartialview中调用。
@model IPagedList<TMS.Models.TMSVirtualMachine>
<div id ="VMTable">
<div class="pagedList" data-tms-target="#VMTable">
@Html.PagedListPager(Model , page => Url.Action("Index","VirtualMachine", new { searchTerm = ViewBag.searchTerm , page,sort = ViewBag.CurrentSortOrder }),
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(PagedListRenderOptions.ClassicPlusFirstAndLast, new AjaxOptions { UpdateTargetId = "VMTable" , LoadingElementId="progress2" }))
</div>
<img src="~/Content/Ajax-loader-bar.gif" class="loadingimage" id="progress2" />
@Html.Partial("~/Views/VirtualMAchine/_VMTable.cshtml",Model)
<img src="~/Content/Ajax-loader-bar.gif" class="loadingimage" id="progress3" />
<div class="pagedList" data-tms-target="#VMTable">
@Html.PagedListPager(Model , page => Url.Action("Index","VirtualMachine", new { searchTerm = ViewBag.searchTerm , page,sort = ViewBag.CurrentSortOrder }),
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(PagedListRenderOptions.ClassicPlusFirstAndLast, new AjaxOptions { UpdateTargetId = "VMTable" , LoadingElementId="progress3"}))
</div>
</div></div></div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$("#ServerSort").click(function () {
$.ajax({
type: "Get",
url: "@Url.Action("Index","VirtualMachine")",
data: { searchTerm: "@ViewBag.searchTerm.ToString()" , page:"1" , sort: "@ViewBag.ServerSortPam" },
//contentType: "application/json; charset=utf-8",
//dataType: "json",
cache: false,
success: successFunc,
error: errorFunc
});
function successFunc(data, status) {
$("#VMTable").html(data);
}
function errorFunc() {
alert('error');
}
})
$("#RackSort").click(function () {
$.ajax({
type: "Get",
url: "@Url.Action("Index","VirtualMachine")",
data: { searchTerm: "@ViewBag.searchTerm.ToString()", page: "1", sort: "@ViewBag.RackSortPam" },
//contentType: "application/json; charset=utf-8",
//dataType: "json",
cache: false,
success: successFunc,
error: errorFunc
});
function successFunc(data, status) {
$("#VMTable").html(data);
}
function errorFunc() {
alert('error');
}
})
});
</script>