在Asp.net MVC中捕获请求动作名称 [英] Capture Requesting Action name in Asp.net MVC
本文介绍了在Asp.net MVC中捕获请求动作名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何在MVC3 / 4中获取请求页面操作名称?
如下所示,我们可以获取请求的操作名称 -
var action ='@ HttpContext.Current.Request.RequestContext.RouteData.Values [action]。ToString()';
等待你的回复。
提前致谢。
How we can get the requesting page action name in MVC3/4 ?
As shown below we can get requested action name as -
var action = '@HttpContext.Current.Request.RequestContext.RouteData.Values["action"].ToString()';
Waiting for your replys.
Thanks in advance.
推荐答案
您需要在ControllerContext而不是RequestContext中搜索它。像这样,
You need to be searching for it in the ControllerContext instead of RequestContext. Like this,
var actionName = ControllerContext.RouteData.Values["Action"].ToString();
I have used this[^] ASP.NET forum post as a reference.
这篇关于在Asp.net MVC中捕获请求动作名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文