Problem description:
In the background, I added a json object to ViewBage in Actoin.
ViewBage. jsonDateMenu = "[{\" id \ ": 2, \" text \ ": \" menu management \ ", \" state \ ": \" open \", \ "iconCls \": null, \ "checked \": true, \ "attributes \": null, \ "children \": [{\ "id \": 3, \ "text \": \ "new menu \", \ "state \": \ "open \", \ "iconCls \": null, \ "checked \": true, \ "attributes \": null, \ "children \": null}, {\ "id \": 5, \ "text \": \ "edit menu \", \ "state \": \ "open \", \ "iconCls \": null, \ "checked \": true, \ "attributes \": null, \ "children \": null}] },{ \ "id \": 4, \ "text \": \ "role permission management \", \ "state \": \ "open \", \ "iconCls \": null, \ "checked \": true, \ "attributes \": null, \ "children \": [{\ "id \": 6, \ "text \": \ "add role \", \ "state \": \ "open \", \ "iconCls \": null, \ "checked \": true, \ "attributes \": null, \ "children \": null}] "System. string
However, the frontend obtains the value through @ ViewBage.
[{& Quot; id & quot;: 2, & quot; text & quot;: & quot; menu management & quot;, & quot; state & quot;: & quot; open & quot;, & quot; iconCls & quot;: null, & quot; checked & quot;: true, & quot; attributes & quot;: null, & quot; children & quot;: [{& quot; id & quot;: 3, & quot; text & quot;: & quot; Create menu & quot;, & quot; state & quot;: & quot; open & quot;, & quot; iconCls & quot;: null, & quot; checked & quot;: true, & quot; attributes & quot;: null, & quot; children & quot;: null}, {& quot; id & quot;: 5, & quot; text & quot;: & quot; edit menu & quot;, & quot; state & quot;: & quot; open & quot;, & quot; iconCls & quot;: null, & quot; checked & quot ;: true, & quot; attributes & quot;: null, & quot; children & quot;: null}] },{ & quot; id & quot;: 4, & quot; text & quot;: & quot; Role permission management & quot;, & quot; state & quot;: & quot; open & quot;, & quot; iconCls & quot ;: null, & quot; checked & quot;: true, & quot; attributes & quot;: null, & quot; children & quot;: [{& quot; id & quot ;: 6, & quot; text & quot;: & quot; add a Role & quot;, & quot; state & quot;: & quot; open & quot;, & quot; iconCls & quot;: null, & quot; checked & quot;: true, & quot; attributes & quot;: null, & quot; children & quot;: null}]
Obviously, double quotation marks are encoded and displayed. This is obviously not the result we want. What we want is output as is,
Solution:
1. @ MvcHtmlString. Create (@ ViewBag. JsonDateMenu). After that, everything is normal !, This method is used to return MVCHtmlString when HtmlHelp is extended.
2. @ Html. Raw (@ ViewBag. JsonDateMenu) Later, I accidentally discovered this method, which solves the problem. I personally prefer this method. Of course, I can also directly perform manual code decoding.
Solution:
Online query
Reference: forgot...