How do I get the MethodInfo of an action, given action, controller and area names?

前端 未结 4 635
被撕碎了的回忆
被撕碎了的回忆 2020-12-06 07:19

What I have is the following extension method:

public MyCustomAttribute[] GetActionAttributes(
    this Controller @this,
    string action,
    string contr         


        
4条回答
  •  情书的邮戳
    2020-12-06 08:12

    if you have a default route configured like

    routes.MapRoute(
            "Area",
            "",
            new { area = "MyArea", controller = "Home", action = "MyAction" }
        );
    

    you can get the route information inside the controller action like

    ht tp://localhost/Admin

    will give you

    public ActionResult MyAction(string area, string controller, string action)
    {
     //area=Admin
     //controller=Home
     //action=MyAction
     //also you can use RouteValues to get the route information
    }
    

    here is a great blog post and a utility by Phil Haack RouteDebugger 2.0

提交回复
热议问题