如何在Asp.NET Core中呈现不同的布局

我想在我的asp.net核心应用程序的某些页面上呈现空布局。为此,我在中使用了此代码_ViewStart.cshtml。


@{

    var controller = HttpContext.Current.Request.RequestContext.RouteData.Values["Controller"].ToString();

    string cLayout = "";

    if (controller == "Empty")

    {

        cLayout = "~/Views/Shared/_Empty_Layout.cshtml";

    }

    else

    {

        cLayout = "~/Views/Shared/_Layout.cshtml";

    }

    Layout = cLayout;

}

这段代码适用于,Asp.NET MVC App但给出的错误.NET Core App。错误是The name 'HttpContext' does not exist in the current context


慕沐林林
浏览 190回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP