【发布时间】:2016-09-28 17:28:51
【问题描述】:
在我的主视图中,我有 ajax 操作链接
例如
@Ajax.ActionLink("Update Hours", "companyhours", "business",
new { Id = ViewBag.Id }, new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "divCurrentView" })
控制器内部
public ActionResult CompanyHours(string Id)
{ ... return PartialView("UpdateCompanyHours", model);}
点击加载视图
我拥有的部分视图“UpdateCompanyHours.cshtml”
@model CompanyHoursVM
@{Layout = null; }
@using (Ajax.BeginForm("CompanyHours", new AjaxOptions { UpdateTargetId = "presult", HttpMethod = "POST", InsertionMode = InsertionMode.Replace }))
{
@Html.ValidationSummary(true)
@Html.AntiForgeryToken()
// i have textboxes and a button - everything loads fine
@Html.CheckBoxFor(model => model.Open247, new { @class = "Time24hrs"})
}
问题来了:
我想在我的主视图中添加我的 js 文件。将代码添加到主视图页面底部:
@section Scripts
{
<script src="~/Scripts/myjs.js"></script>
}
甚至没有@section Scripts 标签
js 文件很简单。第一个警报已执行,但 onclick 没有执行
(function () {
$(function () {
alert("alert1");
$('.Time24hrs').click(function () {
alert("alert2");
});
});
})();
js 无法识别。但是,如果我在局部视图中添加 js 文件,它就可以正常工作
如何让js文件加载到主视图中,并在部分视图中使用js文件?
【问题讨论】:
标签: javascript jquery ajax asp.net-mvc partial-views