2013-05-21 180 views
0

一個微不足道的問題,混合服務器端的代碼,但該解決方案脫離了我此刻的如何剃刀

我們在佈局和CSS(只名稱,沒有擴展名)被從數據庫中檢索到的CMS!

的.cshtml有這個代碼不編譯乾淨

.... 
<link href="~/Content/themes/@ViewBag.dbConfig.Theme/style/@ViewBag.dbConfig.CssName.css" rel="stylesheet">  

其中變量是

ViewBag.dbConfig.CssName 

沒有.css擴展

有沒有一種方法,使這項工作不改變配置?

+0

像JavaScript的eval函數? –

+0

爲什麼不在控制器中構建整個路徑,然後添加到ViewBag? – Jorge

回答

1

首先我會包裝你的變量用法...看看是否產生更符合你的預期。

<link href="~/Content/themes/@(ViewBag.dbConfig.Theme)/style/@(ViewBag.dbConfig.CssName).css" rel="stylesheet"> 
0

使用parantesese和修剪:

<link href="~/Content/themes/@(ViewBag.dbConfig.Theme.trim())/style/@(ViewBag.dbConfig.CssName.trim()+".css")" rel="stylesheet">