MVC 5 Ajax partialView loads in a new page

I had a partialView that submits to the server and then should update the PartailView. It was successfully posting to the server side code, but when the code would return the PartialView, it would display text in a new page rather than putting it back into the old page. This occurred previously when I was trying to return a Javascript result.

 

http://dyball.wordpress.com/2014/04/07/partial-view-using-unobtrusive-ajax-in-mvc-5-loads-into-a-new-page/ saved me. Basically I didn’t have the unobtrusive ajax javascript installed.

I used Nuget to install Microsoft.jQuery.Unobtrusive.Ajax, and that fixed it. I just needed to add a reference to the new js file from my _Layout file right after the unobtrusive.validate script inclusion line.

<script src="@Url.Content(" type="text/javascript"></script><script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s