我有一個項目ASPNET MVC5使用C#通過項目定義不再一致認爲頁面佈局的結構會存儲在數據庫中。使用Razor開發標準模板 - ASPNET MVC
我的_ViewStart內部將被引用_Layouts.cshtml
將是頁面的常見內容。到目前爲止,問題在於內容將是網站結構將從數據庫中提取,包含所有HTML和Razor元素,並呈現在屏幕上。在簡單的HTML(當鴕鳥政策有剃刀),這將很好地工作下列一些替代品(視圖_layouts.cshtml
代碼中ConteudoHTML會從銀行尋求並返回由控制器):
@ViewBag.ConteudoHTML
或@Html.Raw(ViewBag.ConteudoHTML.ToString())
- 創建一些助手,並在視圖中稱:
@MeuHelper.Template(ViewBag.ConteudoHTML.ToString())
的問題是,我存儲在數據庫結構已經包含了我的模型,ViewBag,助手等。當渲染的瀏覽器不承認剃刀引用元素(除此之外,在我看來, e編譯器不會在沒有RenderBody()
的情況下執行,即使我已經將它插入數據庫記錄旁邊)。
任何人都可以幫助我嗎?在數據庫
<!DOCTYPE html>
<html lang="pt-br" xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt-br">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="@ViewBag.MetaDescription" />
<meta name="keywords" content="@ViewBag.MetaKeywords" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>@ViewBag.Title</title>
<!--[if IE]><link rel="shortcut icon" href="~/css/images/favicon.ico"><![endif]-->
<link rel="icon" href="@Url.Content("~/css/images/favicon.png")" />
<link rel="stylesheet" type="text/css" href="@Url.Content("~/css/bootstrap.min.css")" />
@RenderSection("Css", required: false)
</head>
<body>
@RenderBody()
</body>
</html>
控制器代碼
HTML代碼:
public virtual ActionResult Index()
{
ViewBag.ConteudoHTML = "";//HTML vindo do banco, html acima
ViewBag.Title = "Meu título";
ViewBag.MetaDescription = "Description";
ViewBag.MetaKeywords = "Keywords";
return View();
}
查看代碼(_Layouts.cshtml
)
@ViewBag.ConteudoHTML
夫婦搜索詞,應該讓你開始:http://www.bing.com/search?q=asp.net+custom+viewengine和http://www.bing.com /search?q=asp.net+compile+razor+db – 2015-02-05 16:29:51