Is it possible to suppress the layout expressed in _ViewStart.cshtml
using ASP.NET MVC 3 for certain views of an app.
I understand that I can define the layout programmatically in the controller action. Maybe passing in ""
achieves that?
Code in the _ViewStart. cshtml file will only be run for non-layout pages. Code in the _ViewImports. cshtml file will be run for both layout and non-layout pages.
_ViewImports. cshtml file is usually placed in the Views folder.
Yes, even in Partial View also we can set Layout property which turns Partial View as normal View with Layout .
You have two options
1) Use return PartialView()
from controller, it won't take Layout from View start
2) Assign Layout = null,
@{
Layout = null;
}
Check-out this interesting discussion and answer by marcind around this subject
In order not to apply a layout, just assign null to the Layout property in your view:
@{
Layout = null;
}
<!DOCTYPE html>
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With