I have a partial view which can either be requested via an Action (Action2 in the image below), or rendered inside another page with "Html.Action()" (Action1 in the image below). From within the partial (or the partials controller) is there a way to determine which of these two methods were used to render the page?
A partial view is a Razor markup file ( . cshtml ) without an @page directive that renders HTML output within another markup file's rendered output. The term partial view is used when developing either an MVC app, where markup files are called views, or a Razor Pages app, where markup files are called pages.
The major advantage of partial view is that we can reuse the partial view logic.
The partial view is resides under a normal view and this view may have it's own layout page. No need of a layout page for the partial view.
The primary difference between the two methods is that Partial generates the HTML from the View and returns it to the View to be incorporated into the page. RenderPartial, on the other hand, doesn't return anything and, instead, adds its HTML directly to the Response object's output.
You can use ControllerContext.IsChildAction or check DataTokens
whether there is something with key "ParentActionViewContext"
if you don't have access to ControllerContext
.
You should be able to get it from
HttpContext.Current.Request.RawUrl
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