我試圖創建一個HTML助手,通過創建一個靜態類如下:HtmlHelper失蹤?
public static string Crumbs(this HtmlHelper helper, params string[] args) where T : class
{
// ... rest of code goes here.
}
而我調用它像這樣:
<% Html.Crumbs(
Html.ActionLink("Home", "Index", "Home"),
Html.ActionLink("Lists", "Index", "User"),
Html.Encode(Model.List.Name)); %>
然而,鑑於不編譯,因爲我得到以下編譯錯誤:
CS1061: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'Crumbs' and no extension method 'Crumbs' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)
我不明白。我沒有提到你需要在任何地方註冊靜態類的名字空間。我究竟做錯了什麼?
太好了!我喜歡這個事實,你指出了兩種可能的方式。 – 2009-08-11 13:28:47