【发布时间】:2012-04-02 16:20:09
【问题描述】:
我尝试重写和自定义@Html.ActionLink,在此方法的重载之一中,参数是:
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper,
string linkText, string actionName);
我想要类似上面的东西,还需要找到AreaName和ControllerName而不通过参数传递,我认为使用以下内容:
string controller = ViewContext.RouteData.Values["Controller"];
string area = ViewContext.RouteData.DataTokens["Area"];
但错误上升为:
An object reference is required for the non-static field, method, or property
'System.Web.Mvc.ControllerContext.RouteData.get'
显然我使用的是静态的,那么您对在HtmlHelpers 中查找区域名称和控制器名称有何建议?
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-3 razor static html-helper