gpt4 book ai didi

c# - ASP.NET MVC - 来自 Controller 代码的当前操作?

转载 作者:可可西里 更新时间:2023-11-01 08:06:51 24 4
gpt4 key购买 nike

这与最近的另一个问题非常相似:

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

但是,我想从 controller 代码中获取当前操作的名称。

因此,在 Action 调用的函数代码中,我想获取当前 Action 名称的字符串。

这可能吗?

最佳答案

您可以像这样从您的 Controller 类中访问路由数据:

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

或者,如果“action”不是您路线的必需部分,您可以像往常一样对路线数据进行索引。

关于c# - ASP.NET MVC - 来自 Controller 代码的当前操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1408743/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com