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

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

For example, to check if the controller myController called rendering (I think), I can write:

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

In fact, I want to use the same View model for two action methods, for example:

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

thanks for the help

+4
source share
2 answers

You can use ViewData strong> to store the name of the Action from which the view is rendered

OR

Use ViewContext.RouteData.Values["action"] to get the name of an action from RouteData strong>

+8
source

use ViewContext.RouteData.Values["action"]

+3
source

Source: https://habr.com/ru/post/1304968/


All Articles