My reason I want to know this is because I would like to switch the Layout partial view based on whether it was displayed from a controller action or from another page.
t
return PartialView("MyView.cshtml");
will lead to the layout with the necessary menu stripes and other crop sites.
and
@Html.Partial("MyView")
just embeds the content without adding the rest of the page.
so in my default Layout page I have:
@if (this.IsPartial()) { Layout = null; } else { Layout = "_SiteLayout"; } @RenderBody()
here is what i found:
public static bool IsPartialResult(this WebPageBase @this) { return !@this.OutputStack.Any (writer => writer is HttpWriter); }
it probably won’t work in all situations. but it works for me. YMMV / NTN
source share