我嘗試重寫和定製@Html.ActionLink
,在這種方法的重載之一的參數是:查找區域名稱和控制器名稱與ASP.NET MVC3
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
中的區域名稱和控制器名稱?
用於動作只需使用: var actionName = htmlHelper.ViewContext.RouteData.GetRequiredString(「action」); – Roboblob 2012-06-25 09:55:59