In a controller can I detect if I'm "controlling" a View or a partial view?
I have a shared controller that sits between any controller and Controller
, there are things I would only like to happen if its a View rather than a partial view.
Ideally in protected override ViewResult View(...
There are four ways to pass the data from View to Controller which are explained below: Traditional Approach: In this approach, we can use the request object of the HttpRequestBase class. This object contains the input field name and values as name-value pairs in case of the form submit.
Solution 1 There is no difference in the markup between a partial view and a view; the only difference is in how they are delivered to the browser. A partial view is sent via AJAX and must be consumed by JavaScript on the client side, while a View is a full postback. That's it.
MVC by default will find a View that matches the name of the Controller Action itself (it actually searches both the Views and Shared folders to find a cooresponding View that matches). Additionally, Index is always the "default" Controller Action (and View).
Check
ControllerContext.IsChildAction
in your action method, or
filterContext.IsChildAction
in OnActionExecuted
Have a different route for each. /home/about and /home/about/partial that both are routed to the same controller method. Basically, rather than trying to sniff around for things, EXPRESS it explicitly, through a route, or parameter.
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