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. Within the view, I have all my javascript logic defined (@section Scripts
) there as I can't have any in my partial view. The problem is, within my partial view, I wish to call a javascript function that is defined within the view upon success.
Below is my view and partial view
MyView.cshtml
@section Scripts
{
@Scripts.Render("~/plugins/myplugins")
<script>
function callFunctionOutsideThisPartialView() {
//... This doesn't get called
}
</script>
}
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?