Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check which action method rendered the current view (from within the current view)?

Tags:

asp.net-mvc

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

like image 278
Richard77 Avatar asked Dec 22 '22 04:12

Richard77


1 Answers

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

like image 56
Kushal Waikar Avatar answered May 10 '23 19:05

Kushal Waikar