Reputation: 12590
Can an ASP.NET MVC PartialView directly use a Layout?
I have looked at MSDN for PartialViewResult
and compared with ViewResult
:
ViewResult
has a property MasterName
that PartialViewResult
does not.
But.. I can still define the Layout
property in the partial views Razor.
I am currently remediating a large code base with a huge amount of partial views used to fill iframes. Ideally they would be converted to normal views (ideally we would not use iframes) but I was wondering about just adding a layout to these partials to take out the <head>
element at least so that we have more control over the script versioning (everything is replicated in each partial view). I'm looking for a light-touch solution since much of the code is expected to be thrown away.
Upvotes: 2
Views: 2538
Reputation: 2355
Yes, even in Partial View
also we can set Layout
property which turns Partial View
as normal View
with Layout
.
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
Upvotes: 4
Reputation: 124
Yes.
You can use a layout within a layout:
Layout View Layout PartialView
We have an example of this in our codebase.
Upvotes: 0