mvc3 关于ViewBag赋值html字符串到客户端解码的问题

环境:在index.cshtml中使用_core.cshtml模板页

我在index.cshtml中定义:

ViewBag.Class = "<link type=\"text/css\" rel=\"stylesheet\" href=\"@Url.Content(\"~/Content/core/index.css\")\"/>";

在_core.cshtml中引用:

@ViewBag.Class

打开index页面后发现该引用被编码了,显示如下:

&lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;@Url.Content(&quot;~/Content/core/index.css&quot;)&quot;/&gt;

再次测试,在_core.cshtml中如下写:

@HttpUtility.HtmlDecode(ViewBag.Class);
问题依旧

请教如何解决这个问题呢,我希望的是根据不同的页面动态调用不同页面的css样式表

ITMISS
浏览 526回答 2
2回答

繁花不似锦

@html.raw(ViewBag.Class);

慕姐8265434

赞的很。。。
打开App,查看更多内容
随时随地看视频慕课网APP