Search code examples
c#asp.net-mvc-3razorpartial-views

Determine if View is being rendered as Partial


Is there a way to determine if a view is rendering as a partial?

I'm hoping to extend the reuse of a partial that I'm writing by catching this...and if necessary assigning the appropriate layout to the View.

At the moment I'm just rendering it in a div, but I could also see us using it as a modal and possible it's own page.

(the modal shouldn't require any change so no worries there)

EDIT: To clear up what I'm asking.

I'm wondering if there is anyway to determine the difference between a view being rendered by...

/path/to/controller

and

Html.Partial("/path/to/view.cshtml")


Solution

  • Based on @Pheonixblade9 's response and the lack of other answers it doesn't appear like this is possible at the moment. I ended up just binding the Model of the View as bool and pass this value in when rendering the view/partial.