tags:

views:

48

answers:

2

Hello,

I would like to know how to check which action displayed the current View (from the current view).

For instance, to check if controller myController originated the rendering (I guess) I can write:

<% if(ViewContext.Controller is myApplication.Controllers.myController)%>

In fact, I want to use the same View model for 2 actions methods, like this:

<% If( First Action rendered this view){%> 
   // Display this 
<%} else {%> 
   //Display that 
<%}%>

Thanks for helping

+5  A: 

You may use ViewData for storing name of Action from which view is being rendered

OR

Use ViewContext.RouteData.Values["action"] for pulling out the action name out of RouteData

Kushal Waikar
Better would be to put which type of display the action wishes the view to perform. Otherwise, it all feels a bit backwards.
Damien_The_Unbeliever
@Damien - You might be right. But, I've 2 relatively close input operations to do. I just want to use 1 view model, hiding a couple unecessary information at time.
Richard77
+2  A: 

use ViewContext.RouteData.Values["action"]