This article is a mirror article of machine translation, please click here to jump to the original article.

View: 30433|Reply: 3

[Source] ASP.NET MVC assigns Html character escape issues to ViewBag

[Copy link]
Posted on 6/14/2016 6:06:13 PM | | | |


Original html code:

Background Code:



Then, my viewbag stores html code, the front page does not parse html, directly escapes html code, surely, it is the foreground or background needs to escape!

Today, I will summarize for myself, about ViewBag assigning Html format values, but the display on the web page is not normal;

For example, ViewBag.Content = "<p>Hello, I'm testing something now.</p>";

Front Desk <div>page@VIewBag.Content</div>

The result is displayed on the page: <p>Hello, I am testing something now</p>., I found it when I edited through Firefox, the source code is, &lt;p> Hello, I am testing something now. &lt;/p&gt

This is obviously not what we want, and it corresponds to the HTML format field saved to the database through the editor, and the correct style cannot be displayed after taking it out.

I searched the Internet to find a solution

<div>@Html.Raw(ViewBag.Content)</div>

This is the display normal





Previous:SQL XML Getting Started Tutorial
Next:SQLServer implements the universal method of splitting strings
Posted on 6/14/2016 6:24:31 PM |
This kind of question should also be posted
 Landlord| Posted on 6/14/2016 6:51:09 PM |
Gu Yan Posted on 2016-6-14 18:24
This kind of question should also be posted

Archive The next time you encounter this problem, you can quickly find a solution   

It is also a help for those who encounter such problems
Posted on 6/15/2016 3:18:23 PM |
Xiao Zhaozha Posted on 2016-6-14 18:51
Archive The next time you encounter this problem, you can quickly find a solution   

It is also a help for those who encounter such problems

This can be
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com