[英]How to reference outside javascript in a Partial View called by ajax in MVC5?
I've researched on answers on this topic for MVC 3 & MVC 4 and I was hoping to find a solution for MVC 5. I have a view which loads partial view via ajax. 我已经研究了有关MVC 3和MVC 4的此主题的答案,并且希望能找到针对MVC 5的解决方案。我有一个视图,可通过ajax加载部分视图。 Within the view, I have all my javascript logic defined (
@section Scripts
) there as I can't have any in my partial view. 在视图中,我在其中定义了所有JavaScript逻辑(
@section Scripts
),因为我的局部视图中没有任何逻辑。 The problem is, within my partial view, I wish to call a javascript function that is defined within the view upon success. 问题是,在我的局部视图中,我希望在成功后调用视图中定义的javascript函数。
Below is my view and partial view 以下是我的看法和局部看法
MyView.cshtml MyView.cshtml
@section Scripts
{
@Scripts.Render("~/plugins/myplugins")
<script>
function callFunctionOutsideThisPartialView() {
//... This doesn't get called
}
</script>
}
MyPartialView.cshtml MyPartialView.cshtml
@using (Ajax.BeginForm("MyAction", "MyController",
new AjaxOptions
{
HttpMethod = "POST",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "divForPartialView",
OnSuccess = "callFunctionOutsideThisPartialView()"
}, new { @class = "form-inline" }))
{
// Partial View here
}
What is the correct way to access javascript functions that are outside of the partial view in MVC 5? 在MVC 5中访问部分视图之外的javascript函数的正确方法是什么?
如果我没记错的话,只需要在普通视图中渲染局部视图并通过ajax调用加载该普通视图即可,还可以将jQuery添加到普通视图中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.