I have the action method defined like below:
[Route("example-page")]
public ActionResult MyAction()
{
// I want to use "example-page" in here, like a query parameter.
return View();
}
How to get action route value in controller?
I tried it like this:
var routeName = Url.RequestContext.RouteData.Values["action"].ToString();
It returns MyAction
. I couldn't find another way.
From the Microsoft Dev Blogs:
Therefore, use the HttpRequest.Path
to get the virtual path of the current request and it will match the URI mapped to the corresponded controller/action that this route attribute is applied.