ASP.NET MVC RenderPartial is replacing the entire page
I ran into an issue using RenderPartial that was in the end simple to solve but took a bit of time to figure out.
You have your let’s call it the “parent view” that has the Ajax.BeginForm on it as well as the div where you are rendering the partial view by using Html.RenderPartial. When you load the page you see all of the content of your master page, the “parent view”, as well as the partial view. Fantastic. Now you submit the form by clicking a button or however you are doing it so that the partial view controller method is called. This controller method is returning something like PartialView(“PartialViewName”, viewData);. All seems to be working great, and then the browser ends up only displaying the contents of the partial view. Hey, what happened to the master page and the “parent view” content.
As I understand it, the Ajax.BeginForm works is by calling java script functions in MicrosoftAjax.js and/or MicrosoftAjaxMVC.js. I say and/or because I know that you need them both, however, I did not dig into how it all works nor do I really care. ( That is until the next problem🙂 )
In the end the solution is simple. Just make sure that you reference the proper java script files. I ended up putting them in my master page as follows:
Hope that saves you some hair!
Tags: ASP.NET MVCYou can comment below, or link to this permanent URL from your own site.