2015-01-08 85 views
0

這可能會覺得有線,但它沒有考慮我在哪裏MVC HTML擴展錯誤

日上午在HTML Extesions

enter image description here

在@Html得到錯誤,去定義它的引用從

enter image description here

但實際的參考應該從

enter image description here

更有趣的是,我沒有得到擴展性能,如:@ Html.Action,@ Html.ActionLink &更

enter image description here

有已經與Web.config文件檢查,它似乎很好 交叉驗證:

https://stackoverflow.com/questions/24147846/system-web-webpages-html-htmlhelper-does-not-contain-a-definition-for-sitecor

'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'ActionLink

+1

使用兩個步驟解決此問題:1.清除以下臨時文件:C:\ WINDOWS \ Microsoft.NET \ Framework \ v4.X.XXXX \ Temporary ASP.NET Files \ 2.更新VS通過NugePackage ... – Vinod

回答

0

您應該使用MvcHtmlString類來實現剃刀從輕量刑方法。喜歡這個。

我已經爲Spanfor屬性實現了它。你可以通過使用這種方法來實現

下面的代碼將幫助你作爲一個想法。

public static MvcHtmlString SpanFor<TModel, TProperty>(this HtmlHelper<TModel> html, Expression<Func<TModel, TProperty>> expression, object htmlAttributes) 
     { 
      var valueGetter = expression.Compile(); 
      var value = valueGetter(html.ViewData.Model); 

      var span = new TagBuilder("span"); 
      span.MergeAttributes(new RouteValueDictionary(htmlAttributes)); 
      if (value != null) 
      { 
       span.SetInnerText(value.ToString()); 
      } 

      return MvcHtmlString.Create(span.ToString()); 
     } 

我希望這能幫到你。