简体   繁体   English

更改 Asp net core Mvc 2.2 上的默认页面文件夹

[英]Change default page folder on Asp net core Mvc 2.2

is there a way to change the default directory of ".cshtml" files from "Pages" folder to a custom one?有没有办法将“.cshtml”文件的默认目录从“Pages”文件夹更改为自定义目录?

I tried with the following code but it doesn't seem to work我尝试使用以下代码,但它似乎不起作用

services.Configure<RazorViewEngineOptions>(o =>
            {
                o.ViewLocationFormats.Clear();
                o.ViewLocationFormats.Add("/Test/{0}" + RazorViewEngine.ViewExtension);
            });

Thanks in advance.提前致谢。

The following worked for me以下对我有用

 services.AddMvc().AddRazorPagesOptions(options =>
 {
     options.RootDirectory = "/MyPages";
 }

 public void ConfigureServices(IServiceCollection services) { services.AddMvc().WithRazorPagesRoot("/MyPages"); } For details folow the link https://www.talkingdotnet.com/change-asp-net-core-razor-pages-default-directory-name/ public void ConfigureServices(IServiceCollection services) { services.AddMvc().AddRazorPagesOptions(options => { options.Conventions.AddPageRoute("/Employees/Index", ""); }); } For more follow the links https://exceptionnotfound.net/setting-a-custom-default-page-in-asp-net-core-razor-pages/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将区域文件夹中的页面设置为asp.net core 2.2 MVC中的默认页面 - Set Page from Area Folder as default page in asp.net core 2.2 MVC 使用 ASP.NET Core 2.2 的页面名称 - Page names with ASP.NET Core 2.2 设置asp.net核心MVC应用程序的默认页面 - Setting default page for asp.net core MVC application 更改 ASP.NET Core MVC 中的默认 cookie 名称 - Change default cookie names in ASP.NET Core MVC asp.net核心mvc更改默认身份区域路由 - asp.net core mvc change default Identity area routes 在Docker的ASP.NET Core 2.2中将默认时区更改为24h时间格式 - Change default timezone in ASP.NET Core 2.2 on Docker for 24h time format 本地化文件无法在MVC ASP.NET Core 2.2中呈现Razor页面 - Localization file not effective rendering a Razor page in MVC ASP.NET Core 2.2 ASP.NET Core 2.2 MVC MapRoute 项目到 ASP.NET 3.0 端点 MapAreaControllerRoute “无法找到此本地主机页面” - ASP.NET Core 2.2 MVC MapRoute project to ASP.NET 3.0 endpoints MapAreaControllerRoute "This localhost page can't be found" Swagger不显示具有.net Core 2.2 MVC默认项目的端点 - Swagger do not show endpoints with .net core 2.2 mvc default project ASP.Net Core 2.2 升级 - 默认路由重定向问题 - ASP.Net Core 2.2 Upgrade - Default Route Redirection Issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM