2017-05-04 16 views
0

您好我想在MVC中使用HtmlHelper。但它不被認可。所以我嘗試使用System.Web.WebPages.Html添加。但是,在我的代碼中添加此代碼後,AnonymousObjectToHtmlAttributes無法識別。它是否被取消或其他?在MVC中找不到HtmlHelper類

using System; 
using System.Collections.Generic; 
using System.Web; 
using System.Web.Mvc; 
using System.Web.WebPages.Html; 
namespace TestFrame 
{ 
    internal class IframeBuilder 
    { 
     internal static HtmlString Iframe(object htmlAttributes) 
     { 
      IDictionary<string, object> parsedHtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); 

      TestFrame.IframeId = GetId(parsedHtmlAttributes); 

      string parsedIframe = CreateIframeTag(parsedHtmlAttributes); 
      parsedIframe += ReceiveMessageScript(); 
      parsedIframe += SetIframeIdScript(); 

      return new HtmlString(parsedIframe); 
     } 
    } 
+0

您是否添加了必要的參考資料? – Proxy

+0

system.web.mvc你的意思是? – santro

+1

MSDN says [HtmlHelper is in System.Web.Mvc](https://msdn.microsoft.com/en-us/library/system.web.mvc.htmlhelper.anonymousobjecttohtmlattributes(v = vs.118).aspx),而不是'System.Web.WebPages.Html'。 – Filburt

回答

1

HtmlHelperSystem.Web.Mvc的一部分。 這個問題可能是由於您錯過了添加System.Web.Mvc.dll或者dll丟失或者dll有問題導致的。

步驟來解決這個問題:

  1. 確保DLL在參考添加
  2. 確保dll引用是否正確
  3. 確保DLL文件存在
  4. 刪除DLL並重新添加它(如Filburt在評論中所建議的)
+1

可能目標.NET Framework版本不再與Mvc參考版本匹配,因此建議刪除並重新添加System.Web.Mvc引用也許是值得嘗試的一個步驟。 – Filburt

+0

我同意。這也可能是可能的原因。 @Filburt – ViVi