ASP.NET MVC 3 Partial View in layout page ASP.NET MVC 3 Partial View in layout page asp.net asp.net

ASP.NET MVC 3 Partial View in layout page


Instead of:

public ActionResult Index(){    return View(layout);}

do:

public ActionResult Index(){    return PartialView(layout);}

If you don't do that when you return a normal view from your child action, this normal view attempts to include the Layout, which in turn attempts to render the child action, which in turn returns a view, which in turn includes the Layout, which in turn attempts to render the child action, ... and we end up with names like the one ported by this very same site.

Also in your partial you don't need to do double encoding. The @ Razor function already does HTML encode:

@model MyApp.Models.ViewModel.LayoutViewModel<p>    @foreach (var item in Model.navHeader)    {        @item.Name         @item.URL    }</p>


First verify that your child view is inside the Shared directory

@Html.Partial("_LayoutPartial")

OR

 @{Html.RenderAction("actionname", "controller name");}

And don't use @Html.Encode(), Razor is already doing for u. Just use

@item.Name @item.URL


I have solved this error getting on Layout page

System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper

Important !First create partial view inside shared folder

In Controller ,

public PartialViewResult Userdetails(){   ....   return PartialView("PartialViewName", obj);  }

In Layout Page,

@{Html.RenderAction("action","controller");}