英文:
How to set a vertical slice architecture with Razor Pages?
问题
默认情况下,运行时会在Pages
文件夹中查找 Razor 页面,所以您需要这样做:
Pages
--Orders
----index.cshtml
----add.cshtml
--Products
----index.cshtml
----add.cshtml
我该如何改成这样呢?
Orders
--Pages
----index.cshtml
----add.cshtml
Products
--Pages
----index.cshtml
----add.cshtml
英文:
By default the runtime looks for razor pages in the Pages
folder, so you have to do this:
Pages
--Orders
----index.cshtml
----add.cshtml
--Products
----index.cshtml
----add.cshtml
How can I do this instead?
Orders
--Pages
----index.cshtml
----add.cshtml
Products
--Pages
----index.cshtml
----add.cshtml
答案1
得分: 1
这不是一个好主意。您需要指定一个文件夹作为Razor页面的根目录,以便路由正常工作,所以您仍然需要将您的产品和订单文件夹放在其中。如果在根文件夹中有一个名为"Pages"的文件夹,它将成为路由的一部分。所以,您必须覆盖框架生成的所有路由,除非您想要像这样的路由:
/orders/pages/add
第一个文件夹结构在垂直切片中运行良好。这是我做的方式。
英文:
This isn't a great idea. You need to specify one folder as the root for your Razor pages so that routing works so you still need to put your products and orders folder in that. And if you have a Pages folder in that root folder, it will become part of the route. So then you have to override all the routes that get generated by the framework unless you want to have routes like this:
/orders/pages/add
The first folder structure works fine with vertical slices. It's how I do it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论