动态呈现视图的布局

时间:2016-03-09 13:29:42

标签: asp.net-mvc razor

AI有一个使用ASP.NET MVC开发的Web应用程序,它有一个特定的URL,即https://(myapp.com//ProductionLogs/GetTop25Logs,用户无需登录即可访问。我有两个布局1.VANILLA和2.CHOCO设计使用剃刀。如果用户尚未登录,我想显示VANILLA布局,键入上面提到的URL并显示已登录用户的CHOCO布局。

但我无法做到这一点。始终显示CHOCO布局以下是代码:

// Inside LogsController.cs
    public action GetTop25Logs()
    {            
        bool isPlainLayout = IfNotLoggedInShowVanillaLayout();
        ViewBag.PLAINLAYOUT = isPlainLayout;
        return View("Top25Logs");
    }
    public bool IfNotLoggedInShowVanillaLayout()
    {
        return !Request.IsAuthenticated;
    }

//Inside Top25Logs.cshtml
    @{
        if (ViewBag.PLAINLAYOUT)
        {    Layout = "~/Views/Shared/_LayoutVANILLA.cshtml";}
        else
        {    Layout = "~/Views/Shared/_LayoutCHOCO.cshtml";}
    }

0 个答案:

没有答案
相关问题