Rendering a View without its Masterpage

Last post 07-04-2009 9:38 AM by Freakish_05. 2 replies.

Sort Posts:

  • Rendering a View without its Masterpage

    07-03-2009, 2:16 PM
    • Member
      101 point Member
    • Freakish_05
    • Member since 02-03-2008, 2:30 PM
    • Bristol, England
    • Posts 47

    Hi all,

    All of my views need to have masterpages associated with them so that if a client is browsing without ajax support the site still works.

    But for clients supporting ajax sometimes I need to render just the view to inject into the content div of my masterpage.

    How do I do this?

    I've tried taking the masterpage attribute of the page header, this works when I use return View("ViewFile", "~/Path/To/MasterPage.Maser"); but when I use return View("ViewFile") I get a HttpException: Content controls are only allowed in pages that reference a masterpage.

    Many thanks,

    Jason

  • Re: Rendering a View without its Masterpage

    07-03-2009, 4:38 PM
    Answer
    • Contributor
      2,347 point Contributor
    • CodeHobo
    • Member since 08-17-2005, 6:58 PM
    • Southern California
    • Posts 362

    Why don't you create a master page specifically for ajax requests. Even if it's a bare bones page with just the content controls? Then for ajax requests just return View("ViewFile", "~/Path/To/AjaxMasterPage.Master");

    If your view has content controls I think you need a master page, even if it's a very simple stripped down version.

  • Re: Rendering a View without its Masterpage

    07-04-2009, 9:38 AM
    • Member
      101 point Member
    • Freakish_05
    • Member since 02-03-2008, 2:30 PM
    • Bristol, England
    • Posts 47

    Thanks CodeHobo!  That worked perfectly!

Page 1 of 1 (3 items)