解决方法
根据您的评论和您链接的原始主题,我认为您希望使用Url帮助程序获取表单操作的URL,但我可能误解了您的需求:
在视图中:
@Url.Action(null) returns the current controller/action @Url.Action("Action") returns a custom action with current controller @Url.Action("Action","Controller") returns a custom controller and action
在HTML帮助器中:
public static MvcHtmlString MySpecialHelper(this HtmlHelper htmlHelper) { UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext,htmlHelper.RouteCollection); string url = urlHelper.Action("Controller","Action"); //To get the action based on the current Action/Controller use: url = urlHelper.Action(htmlHelper.ViewData["action"] as string); //or url = urlHelper.Action(null); return new MvcHtmlString(url); }