In Asp.net, the grid that uses extjs does not display HTML content.

Source: Internet
Author: User

Recently, I used Asp.net in combination with extjs to develop a news publishing module. I found that extjs grid could not display HTML-tagged news content, and I was puzzled. There were no errors in ff and IE, in addition, in FF debugging, the news content data has been taken out, and the JSON format is correct, but it is not displayed.

 

Strange!

After repeated research, we found a detail. We copied the news directly from the webpage and pasted it into extjs's htmleditor. The release will contain a lot of \ r \ n tags, as long as it drops, it will be OK, and \ is an escape character, to be processed, otherwise it will not be displayed.

Although the JSON format is simple, it must be organized, otherwise it will not be displayed.

Solution:

It's easy. You only need to replace the news content field. The method to view my ilist2json is as follows:

Public String tojsonstring <t> (string jsonname, ilist il)
{
Stringbuilder JSON = new stringbuilder ();
JSON. append ("{" + jsonname + ":[");
If (IL. Count> 0)
{
For (INT I = 0; I <Il. Count; I ++)
{
T OBJ = activator. createinstance <t> ();
Type type = obj. GetType ();
Propertyinfo [] Pis = type. getproperties ();
JSON. append ("{");
For (Int J = 0; j <PIs. length; j ++)
{
String ilvalue = "";
If (PIS [J]. getvalue (IL [I], null )! = NULL)
{
Ilvalue = Pis [J]. getvalue (IL [I], null ). tostring (). replace ("'","\""). replace ("\ r ",""). replace ("\ n ",""). replace ("\\

', "//"); // The Key is here. Replace the sensitive character with OK.
}
JSON. append ("'" + Pis [J]. Name. tostring () + "': '" + ilvalue + "'");
If (j <PIs. Length-1)
{
JSON. append (",");
}
}
JSON. append ("}");
If (I <Il. Count-1)
{
JSON. append (",");
}
}
}
JSON. append ("]}");
Return JSON. tostring ();
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.