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.

Situation

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🙂 )

Solution

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:

<head runat="server">
    <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
    <title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
    <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
</head>

Hope that saves you some hair!
Tom

Explore posts in the same categories: .NET, ASP.NET MVC

Tags:

You can comment below, or link to this permanent URL from your own site.

3 Comments on “ASP.NET MVC RenderPartial is replacing the entire page”


  1. […] Here is the original:  ASP.NET MVC RenderPartial is replacing the entire page « Tom Krueger […]

  2. RT Says:

    I noticed something different, but related.

    My environment: XP-SP3-Prof / VS2008-SP1 Prof / MVC 1.0 RTM

    When I refactor JavaScript into a Partial view, the page content from the parent page disappears.

    I’ve to mouse over where the links would’ve been placed for them to appear. H2 tag content appears when I mouse over the tab corresponding to the page.

    I’ve tried multiple things so far including your solution above. Even an empty script or a script with an alert statement create the issue.

    I hope it is not an issue with MVC 1.0.

  3. RT Says:

    An update:

    Even an in-page script (no refactoring) is causing the same issue.

    I believe the presence of SCRIPT tags in the header and SCRIPT tags in the body is the issue.


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


%d bloggers like this: