VB.net 通过 MVC 站点中的 ViewBag 传递 grid-template-areas 和 grid-template-columns 值

VB.net pass grid-template-areas and grid-template-columns values via ViewBag in MVC site

我有一个使用 VB.net MVC 5 的初期网站,在 _layout 页面中我有我的主要结构(页眉、导航、页脚等)。标签也在布局页面中,视图页面中唯一的东西是正文 html。我正在使用网格来排列我的内容元素,并且我正在尝试弄清楚如何在每页的基础上设置网格模板区域和网格模板列值。目前,以下样式包含在布局页面中。

<style>
    .cc-grid {
        grid-template-columns: 50% 50%;
        grid-template-areas: 'cap1 cap1' 'cap2 cap3' 'cap4 cap3';

    }
</style>

我尝试的是使用 viewBag 参数将网格模板区域字符串 ('cap1 cap1' 'cap2 cap3' 'cap4 cap3') 作为 属性 传递以下:

grid-template-areas: @ViewBag.Areas;

然后在实际内容中赋值使用:

@ViewBag.Areas = "'cap1 cap1' 'cap2 cap3' 'cap4 cap3'"

字符串的值已传递(我通过将 @ViewBag.Areas 放入

标记进行测试,它确实显示了正确的字符串。这似乎是呈现值的问题CSS.

如果无法在 CSS 中使用 ViewBag,在每页基础上与在布局页面中设置这种样式属性的最佳方法是什么?

当我在 Edge 中检查页面时,它呈现如下:

grid-template-areas: &#39;cap1 cap1&#39; &#39;cap2 cap3&#39; &#39;cap4 cap3&#39;;

所以看起来单引号被呈现为 '.

提前致谢,

特里

感谢这个回答:

Javascript, Razor and Escape characters. Like apostrophe

基本上我不得不这样使用html.raw:

ViewBag.Areas = Html.Raw("'cap1 cap1' 'cap2 cap3' 'cap4 cap3'")