2014-05-01 70 views
0

如何進行的觀點,而不是母版頁名稱 佈局例如,而不是如何構建動態佈局mvc 4?

return View("Index", "_Layout"); 

使用返回剃刀碼驗證碼

return View("Index", @" 

@using System.Diagnostics 
@using iaumahallat.Helper 
<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <title>@ViewBag.SiteTitle - @ViewBag.Title</title> 
    <meta name="description" content="@ViewBag.MetaDescription"> 

    @Scripts.Render("~/bundles/modernizr") 

</head> 
<body> 

      @RenderBody() 

    @RenderSection("scripts", required: false) 



</body> 
</html> 


"); 
+0

你不能,因爲這不是一個有效的字符串;) –

回答

0

的一種方法是使用RazorEngine和解析剃刀源代碼,然後獲取相應的Html字符串以將其顯示在視圖或佈局上 -

Razor.SetTemplateBase(typeof(HtmlTemplateBase<>)); 

    string template = 
    @"<html> 
     <head> 
     <title>Hello @Model.Name</title> 
     </head> 
     <body> 
     Email: @Html.TextBoxFor(m => m.Email) 
     </body> 
    </html>"; 

    var model = new PageModel { Name = "World", Email = "[email protected]" }; 
    string result = Razor.Parse(template, model); 

然後使用result在您感興趣的頁面。