How to get string action and controller names from UrlHelper

I have

public MvcHtmlString(this UrlHelper url)
{
    string controller = //???
    string action = //????
}

Does anyone know a solution?

+3
source share
1 answer

Try the following:

string controller = url.RequestContext.RouteData.Values["controller"];
string action = url.RequestContext.RouteData.Values["action"];
+5
source

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


All Articles