ASP.NET MVC - 从控制器code电流动作? [英] ASP.NET MVC - Current Action from controller code?
问题描述
这是非常相似的另一个最近的问题:
This is very similar to another recent question:
<一个href=\"http://stackoverflow.com/questions/362514/asp-net-mvc-current-action\">http://stackoverflow.com/questions/362514/asp-net-mvc-current-action
不过,我想从内部获得当前操作名称的控制器的code。
However, I want to get the name of the current action from within controller code.
因此,一个说是被一个行动调用的函数的code范围内,我想获得当前操作名称的字符串。
So within the code of a function that's being called by an Action, I want to get a string of the name of the current Action.
这可能吗?
推荐答案
您可以从控制器类中访问路径数据是这样的:
You can access the route data from within your controller class like this:
VAR actionName = ControllerContext.RouteData.GetRequiredString(行动);
或者,如果行动是不是你的路线的必要组成部分,你可以索引,按通常的路线数据。
Or, if "action" isn't a required part of your route, you can just index into the route data as per usual.
这篇关于ASP.NET MVC - 从控制器code电流动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!