我尝试重写并自定义@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
中如何查找区域名称和控制器名称?