2016-01-08 76 views
0

所有如果我發送數據<test>其獲得轉換爲html標籤<test></test>請幫助!InnerHtml正在轉換特殊字符爲html標籤在asp.net mvc

public static MvcHtmlString AnchorRowSelection(this HtmlHelper helper, string displayText, string title, string CssClass, string onclick, bool isModernPortal) 
    { 
     string className = ".body-row"; 
     // Building anchor tag html 
     var Anchor = new TagBuilder("a"); 
     // if(!string.IsNullOrWhiteSpace(displayText)) 
     Anchor.InnerHtml = ControlUtilities.EncodeEmptyText(displayText); 
     if(!string.IsNullOrWhiteSpace(title)) 
      Anchor.Attributes.Add("title", title); 
     if(!string.IsNullOrWhiteSpace(CssClass)) 
      Anchor.Attributes.Add("class", CssClass); 
     if(!string.IsNullOrWhiteSpace(onclick)) 
     { 
      string onclickString = string.Format("Javascript:highliteRowSelection(this, '{0}');{1}", className, onclick); 
      Anchor.Attributes.Add("onclick", onclickString); 
     } 
     return MvcHtmlString.Create(Anchor.ToString(TagRenderMode.Normal)); 
    } 

我改變內部HTML設置內的文本,但如果你想在XML解析器不解析在你看來,你有兩個選擇逃離這個XML標籤我面臨的其他一些問題

+0

我不知道你問什麼?你能詳細解釋一下嗎? – ramiramilu

+0

我想發送數據爲< test >錨定標記字段,但它獲得轉換爲html標記 – user3675493

回答

0

<html><![CDATA[This is <b>bold</b>]]></html> 

<html>How to escape &lt;b&gt;bold&lt;/b&gt;</html> 

轉義文本意味着整個HTML塊將是一個大的文本節點。包裝在CDATA中告訴XML解析器不要解析該節。這可能是「更容易」,但限制你的能力,只適用於適當的情況;不僅僅因爲它更方便。轉義標記被認爲是有害的。

Reference

+0

我發現當你嘗試操縱它雖然第一個選項會產生非常不一致的結果。例如,當您解析文檔並嘗試提取''的內容時,我發現一些實現會自動刪除'<!CDATA ['符號和一些將其留在返回的字符串中。非常令人沮喪。 – Matthew