Reputation: 6073
I have an entire Web Application built using ASP.NET MVC and have a _ViewStart.cshtml
page that specifies a Layout.
This works great for my entire site. However, I have a single prototype static HTML page that I just need to dump into a directory.
I copied the HTML into a CSHTML file and fronted it with a controller. The problem is that when I go to this page, it is using the Layout.
How can I configure it so that I can just serve this page up as static, standalone content without the Layout from _ViewStart
?
Upvotes: 0
Views: 1626
Reputation: 218732
By default, all views will use the layout from ~/Views/Shared
as it is specified in the _Viewstart.cshtml
file. Every time a view is executed, the code inside the _Viewstart.cshtml
will be executed which sets the layout for the view.
If you do not want to execute/include the layout for a specific view, you can explicitly set layout as null
on a view. Add the below code to the view.
@{
Layout = null;
}
Keep in mind that, even though it is static html in your cshtml
file, user will not/should not directly access this view (like a normal html page/htm page). It has to be routed via an action method which returns this cshtml
view.
Another option is to use the PartialView
method instead of View
method. When using the PartialView method to render a view, the framework do not run _ViewStart.cshtml
, hence you get the same result.
public ActionResult About()
{
return PartialView();
}
PartialView
is really handy when you want to render the markup for parts of your page (Ex : content of for a modal dialog etc)
Upvotes: 5