ASP.NET MVC - Current Action from controller code?

后端 未结 3 1442
感动是毒
感动是毒 2021-02-07 20:13

This is very similar to another recent question:

How can I return the current action in an ASP.NET MVC view?

However, I want to get the name of the current actio

3条回答
  •  不要未来只要你来
    2021-02-07 20:47

    You can access the route data from within your controller class like this:

    var actionName = ControllerContext.RouteData.GetRequiredString("action");

    Or, if "action" isn't a required part of your route, you can just index into the route data as per usual.

提交回复
热议问题