locked
Custom View Location in asp.net core 5 RRS feed

  • Question

  • User-183185495 posted

    I am using .net 5 for a asp.net web site and I want to have a my themes in and orginized way.

    I want to have 

    Theme\ThemeName\_Layout.cshtml this would be even used for say if the user went to the Home Controller

    But at present no matter what i am doing its looking for it here

    InvalidOperationException: The layout view ' ~/Views/Shared/FrontEnd/_Layout.cshtml' could not be located. The following locations were searched: /Views/Home/ ~/Views/Shared/FrontEnd/_Layout.cshtml

    Is thee a way to have a custom view location by the way I am using razor pages cshtml.

    My startup.cs route data is

                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllerRoute(
                        name: "default",
                        pattern: "{controller=Home}/{action=Index}/{id?}");
                });

    Sunday, December 27, 2020 8:41 PM

All replies

  • User1686398519 posted

    Hi roguenidb, 

    I am using razor pages

    Do you want to specify the Layout view? Razor views have a Layout property. Individual views specify a layout by setting this property.

    If your project is a Razor Pages application, you only need to add this code to the Index page:

    @{
        Layout = "/Pages/Shared/Theme/ThemeName/_Layout.cshtml";
    }

    But according to the Startup.cs code you provided, your project looks like an MVC application,you need to add this code to the Index view:

    @{
        Layout = "/Views/Shared/Theme/ThemeName/_Layout.cshtml";
    }

    Best Regards,

    YihuiSun

    Monday, December 28, 2020 7:44 AM