在视图中有侧栏。单击某个项目时,相应的视图将作为部分视图加载到我的主视图中。在我的局部视图中,我使用jquery插件(fixedHeaderTable)来渲染表。加载视图时,默认情况下会加载第一个侧面菜单项视图。这很好用。但是如果我导航到另一个侧面菜单并单击第一个侧面菜单项,我的视图会被渲染,但它说它无法访问jquery插件方法。
我的主视图我加载局部视图的位置。当我从chrome检查页面时,我可以看到jquery插件已加载。
@model App.Core.DataAccess.ViewModel.TimeTrackerViewModel
@{
ViewBag.Title = "Reports";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript" >
function onSideMenuClick(selectedItem) {
if (selectedItem.id === 'timetracker') {
$.get("@Url.Action("TimeTracker", "Reports")", function (data) {
$('#divProduct').html(data);
});
$('#TimeTracker').fixedHeaderTable({
altClass: 'odd',
fixedColumns: 1,
autoResize: true,
create: function () {
$(".fht-fixed-body>.fht-tbody").niceScroll({ styler: "fb", cursorcolor: "#7e7d7d" });
}
});
}
else if (selectedItem.id === 'tabPatientFlowSummary') {
$.get("@Url.Action("PatientFlowSummary", "Reports")", function (data) {
$('#divProduct').html(data);
});
$('#PatientFlowSummary').fixedHeaderTable('destroy');
$('#PatientFlowSummary').fixedHeaderTable({
altClass: 'odd',
fixedColumns: 1,
autoResize: true
});
}
else if (selectedItem.id === 'tabProductionCollectionSummary') {
$.get("@Url.Action("Index", "ProductionCollectionSummary")", function (data) {
$('#divProduct').html(data);
});
}
else if (selectedItem.id === 'tabInpurReport') {
$.get("@Url.Action("DailyCollection", "Reports")", function (data) {
$('#divProduct').html(data);
});
}
else if (selectedItem.id === 'tabMidYearReport') {
$.get("@Url.Action("MidYearReport", "Reports")", function (data) {
$('#divProduct').html(data);
});
}
else {
$.get("@Url.Action("AnnualReport", "Reports")", function (data) {
$('#divProduct').html(data);
});
}
}
</script>
@section SideBar{
<section class="sidebar">
<a href="#" id="sidebarToggle">Sidebar Toggle</a>
<div class="sidebar-content">
<ul class="sidebar-menu">
<li><a href="#" onclick="onSideMenuClick(this);" id="timetracker" class="active" ><i class="icon-patient_flow_summary"></i>Time Tracker</a></li>
<li><a href="#" onclick="onSideMenuClick(this);" id="tabPatientFlowSummary" ><i class="icon-patient_flow_summary"></i>Patient Flow Summary </a></li>
<li><a href="#" onclick="onSideMenuClick(this);" id="tabProductionCollectionSummary" >Production Collection Summary</a></li>
<li><a href="#" onclick="onSideMenuClick(this);" id="tabInpurReport"><i class="icon-daily-collection"></i>Daily Collection </a></li>
<li><a href="#" onclick="onSideMenuClick(this);" id="tabMidYearReport"><i class="icon-mid_year_report" ></i>Mid Year Report </a></li>
<li><a href="#" onclick="onSideMenuClick(this);" id="tabAnnualReport"><i class="icon-annual_report"></i>Annual Report</a></li>
</ul>
</div>
</section>
}
<div id="divProduct" class="main-content-area-wap width-sidebar clearfix">@Html.Action("TimeTracker","Reports")</div>
我的控件如图所示
public PartialViewResult TimeTracker()
{
DateTime dt = DateTime.Now;
if (timetrackerViewModel == null)
{
timetrackerViewModel = new TimeTrackerViewModel();
}
timetrackerViewModel.lstHrsAval = new List<decimal>();
timetrackerViewModel.HoursWorked = new List<decimal>();
timetrackerViewModel.NoOfVisits = new List<decimal>();
for (int i = 1; i <= 10; i++)
{
timetrackerViewModel.lstHrsAval.Add(i);
timetrackerViewModel.HoursWorked.Add(i);
timetrackerViewModel.NoOfVisits.Add(i);
}
return PartialView("_TimeTrackerPartial", timetrackerViewModel);
}
我正在我的_layout View中加载我的所有脚本文件,jquery,jquery插件。我做错了什么。