How to get the current ASP.NET core controller method name inside the controller using Reflection or another accurate method

后端 未结 5 1555
深忆病人
深忆病人 2021-02-12 17:40

I want to get the current method name of my ASP.NET Core controller

I have tried getting the method name through reflection:

    [HttpGet]
         


        
5条回答
  •  别跟我提以往
    2021-02-12 18:22

    In ASP.NET Core it seems to have changed and you have to use the ActionName property

    ((Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor)ViewContext.ActionDescriptor).ActionName;
    

提交回复
热议问题