Asp.net mvc - How to define a child action to ignore the layout

I am using @Html.Action() to render a child action in my view.

The _ViewStart.cshtml file indicates that all views should use a specific layout, for example:

 @{ Layout = "~/Views/Shared/_Layout.cshtml"; } 

The problem is that the layout also applies to my child action, so the last page ends with two headers and two footers. How to prevent this?

+8
layout asp.net-mvc asp.net-mvc-3
source share
2 answers

2 possibilities:

  • return PartialView() from the corresponding controller action instead of return View()

  • Delete the layout in the view itself

     @{ Layout = null; } 
+19
source share

It seems you want to use ChildActionOnly and don't want to pass the model from the view, then you cannot use PartialView.

If so, you need to manually delete the layout

 @{ Layout = ""; } 
0
source share

All Articles