如何在razor中混合服务器端代码
本文关键字:混合 服务器端 代码 razor | 更新日期: 2023-09-27 18:14:48
一个微不足道的问题,但目前我想不出解决方案
我们有一个CMS,其中布局和CSS(只有名称,没有扩展)是从数据库检索!
.cshtml有这段代码,编译不干净
....
<link href="~/Content/themes/@ViewBag.dbConfig.Theme/style/@ViewBag.dbConfig.CssName.css" rel="stylesheet">
,其中变量为
ViewBag.dbConfig.CssName
没有。css扩展名
有没有一种方法可以让这个工作而不改变配置?
首先我要包装你的变量用法…看看结果是否更符合你的预期。
<link href="~/Content/themes/@(ViewBag.dbConfig.Theme)/style/@(ViewBag.dbConfig.CssName).css" rel="stylesheet">
使用括号和边框:
<link href="~/Content/themes/@(ViewBag.dbConfig.Theme.trim())/style/@(ViewBag.dbConfig.CssName.trim()+".css")" rel="stylesheet">