2012-03-18 53 views

回答

3

一種方法是覆蓋所需視圖中的佈局。

/Views/Home/Index.cshtml

@{ 
    Layout = "~/Views/Shared/_layout.cshtml"; 
} 

或者你可以做到這一點在控制器

/Controllers/Home.cs

public ActionResult Index() 
{ 
    ViewResult result = this.View(); 
    // i think this is correct and it shouldn't need a full/relative path 
    result.MasterName = "_layout.cshtml";  
    return result; 
} 

這是假設您的_ViewStart.cshtml文件如下所示:

@{ 
    Layout = "~/Views/Shared/_layout-content.cshtml "; 
} 
+0

我只是想我的2美分加入ERIKS答案, 如果u想決定前往 控制你可以使用startPage.cshtml例如,問 @ {如果(請求之前要使用的佈局。 IsAuthenticated)Layout = ******;其他佈局= &&&&;} – Liran 2012-03-18 12:26:18

+0

我會測試一下,並讓你知道結果。 @Liran - 我也會試試這個,謝謝你的輸入。 – 2012-03-18 19:48:15

相關問題