标签:
问题描述:
后台,Actoin中我向ViewBage中加入了一个json
ViewBage.JsonDateMenu ="[{\"id\":2,\"text\":\"菜单管理\",\"state\":\"open\",\"iconCls\":null,\"checked\":true,\"attributes\":null,\"children\":[{\"id\":3,\"text\":\"新建菜单 \",\"state\":\"open\",\"iconCls\":null,\"checked\":true,\"attributes\":null,\"children\":null},{\"id\":5,\"text\":\"编辑菜单\",\"state\":\"open\",\"iconCls\":null,\"checked\":true,\"attributes\":null,\"children\":null}]},{\"id\":4,\"text\":\"角色权限管理\",\"state\":\"open\",\"iconCls\":null,\"checked\":true,\"attributes\":null,\"children\":[{\"id\":6,\"text\":\"新增角色\",\"state\":\"open\",\"iconCls\":null,\"checked\":true,\"attributes\":null,\"children\":null}]}]" System.String
但是前台通过@ViewBage取到的值是这样的
[{"id":2,"text":"菜单管理","state":"open","iconCls":null,"checked":true,"attributes":null,"children":[{"id":3,"text":"新建菜单","state":"open","iconCls":null,"checked":true,"attributes":null,"children":null},{"id":5,"text":"编辑菜单","state":"open","iconCls":null,"checked":true,"attributes":null,"children":null}]},{"id":4,"text":"角色权限管理","state":"open","iconCls":null,"checked":true,"attributes":null,"children":[{"id":6,"text":"新增角色","state":"open","iconCls":null,"checked":true,"attributes":null,"children":null}]}]
很明显,双引号被编码了显示出来,这样很明显不是我们要的效果,我们要的是原样输出,
解决方案:
1. @MvcHtmlString.Create(@ViewBag.JsonDateMenu),这样之后,一切正常了!,一般扩展HtmlHelp的时候返回MVCHtmlString 都是使用的这个方法
2. @Html.Raw(@ViewBag.JsonDateMenu) 后来,无意中发现了这个方法,一样解决了问题,个人这个方式更好,当然还可以直接人工代码解码
解决途径:
网上查询
参考资料:忘了...
标签:
原文地址:http://www.cnblogs.com/dmyao/p/4998275.html