Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc - How to tell child action to ignore layout

I'm using @Html.Action() to render a child action within my view.

The _ViewStart.cshtml file specifies that all views should use a particular layout like this:

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

Problem is, that layout is getting applied to my child action too, so the final page ends up with two headers and two footers. How do I prevent this?

like image 263
David Avatar asked Jan 10 '13 15:01

David


2 Answers

2 possibilities:

  1. return PartialView() from the corresponding controller action instead of a return View()

  2. Blank out the layout in the view itself

    @{
        Layout = null;
    }
    
like image 134
Darin Dimitrov Avatar answered Oct 21 '22 13:10

Darin Dimitrov


Seems you want to use ChildActionOnly and don't want to pass the model from view then you can not user PartialView.

If it is so, you need to remove the layout manually

@{
    Layout = "";
}
like image 36
Ali Adravi Avatar answered Oct 21 '22 11:10

Ali Adravi