0

All if i send data <test> its getting converted as html tags <test></test> please help!!

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));
    }

i changed inner html to set inner text but i am facing some other issues

Lewis Hai
  • 1,086
  • 10
  • 22

1 Answers1

0

If you want the XML parser not to parse the XML tags in your view you have two options to escape this.

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

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

Escaped text means that the entire HTML block will be one big text node. Wrapping in CDATA tells the XML parser not to parse that section. It may be "easier", but limits your abilities downrange and should only be employed when appropriate; not just because it is more convenient. Escaped markup is considered harmful.

Reference

Community
  • 1
  • 1
Joshua Duxbury
  • 3,882
  • 2
  • 26
  • 49
  • I've found that the first option produces wildly inconsistent results when you try manipulating it though. For example when you parse the document and try to extract the content of `` I find some implementations automatically remove the ` – Matthew Jan 11 '16 at 13:44