Solve ASP.net MVC3 and fusioncharts garbled problem

Source: Internet
Author: User

Program code

The code is as follows Copy Code
<script type= "Text/javascript" >
$ (document). Ready (function () {
var myChart = new Fusioncharts ("/fusioncharts/fcf_msline.swf", "MyChart1", "720", "300");
Mychart.setdataurl ("/portal/getuserstat");
Mychart.render ("Charts1");
})
</script>



Intuition is associated with character encoding. In the browser, the MVC interface data is saved as an XML file, Fusioncharts directly call the XML file is also garbled, and then use UltraEdit Open XML Save as UTF8 with BOM file, the chart shows normal, before and after two XML files:



In order to ensure that the BOM is not in the browser to save the last loss, the HTTP data grab packet, determine the server response when there is no BOM:



Now can be sure because the MVC output of the content of the lack of BOM lead to garbled, how to change it? Find code:
  code is as follows copy code
return Content (str," Text/xml ", Encoding.UTF8);

change to:
  code is as follows copy code
return Content (str," Text/xml ", New UTF8Encoding (true));

is still missing BOM garbled, and the last modification is resolved as follows:
  code is as follows copy code

 

respon Se. Write (Encoding.UTF8.GetString (new byte[] {0xEF, 0xBB, 0xBF}));
Return Content (str, "Text/xml", Encoding.UTF8);

 


The above test uses Fusioncharts free-ver 2.2.
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.