问题描述
学习新事物需要时间、空间和精力的投入.我目前正在学习 Asp.Net Core MVC 2.0.此ASP.NET Core 教程概述 指出:
Learning new things needs an investment of time, space and energy. I am currently learning Asp.Net Core MVC 2.0. This ASP.NET Core tutorials overview states:
Razor Pages 是使用 ASP.NET Core 创建 Web UI 的推荐方法
Razor Pages is the recommended approach to create a Web UI with ASP.NET Core
这些信息让我在决定是否必须停止学习 Asp.net Core MVC 并开始学习 Asp.net Core Razor Pages 时感到困惑.
This information confused me in deciding whether I have to stop learning Asp.net Core MVC and start learning Asp.net Core Razor Pages.
- 为什么推荐使用 Razor Pages 在 Asp.net Core 中创建 Web UI?
欢迎任何方向.
推荐答案
Razor 页面针对基于页面的工作流进行了优化,并且可以在这些场景中使用,其移动部件比传统 MVC 模型少.这是因为您不需要处理控制器、操作、路由、视图模型和视图(就像您通常那样).相反,您的路线是基于约定的,并且您的 PageModel 可作为您的 Controller、Action(s) 和 ViewModel 合而为一.当然,页面取代了视图.您也不必像在 MVC 中那样拥有那么多文件夹,从而进一步简化您的项目.
Razor Pages are optimized for page-based workflows and can be used in these scenarios with fewer moving parts than traditional MVC models. This is because you don't need to deal with Controllers, Actions, Routes, ViewModels, and Views (as you typically would). Instead your route is convention-based, and your PageModel serves as your Controller, Action(s), and ViewModel all in one. The page, of course, replaces the View. You also don't have to have as many folders as you would in MVC, further simplifying your project.
来自 ASP.NET Core - 使用 Razor 页面的更简单的 ASP.NET MVC 应用程序,2017 年 9 月 MSDN 文章,作者 Steve Smith一个>:
From ASP.NET Core - Simpler ASP.NET MVC Apps with Razor Pages, a Sept. 2017 MSDN article by Steve Smith:
[Razor Pages] 提供
[Razor Pages] provide
- 在 ASP.NET Core 应用程序中组织代码的更简单方法,使实现逻辑和视图模型更接近视图实现代码.
- 它们还提供了一种更简单的方式来开始开发 ASP.NET Core 应用程序,
那篇文章提供了有关为什么将 Razor Pages over MVC 用于基于页面的工作流的更多信息.显然,对于 API,您仍然希望使用控制器.
That article has more information on why to use Razor Pages over MVC for page-based workflows. Obviously, for APIs, you will still want to use Controllers.
ASP.NET Core - ASP.NET Core MVC 的功能切片,2016 年 9 月的一篇较早的 MSDN 文章描述了为什么用于组织视图和控制器的经典 MVC 约定可能对大型项目不利.本文给出了四个松散相关的应用程序概念的示例:忍者、植物、海盗和僵尸.本文概述了一种在默认文件夹约定之外构建它们的方法,方法是按功能或责任区域将文件组织到文件夹中.
ASP.NET Core - Feature Slices for ASP.NET Core MVC, an older MSDN article from Sept. 2016, describes why the classical MVC convention to organize views and controller might have disadvantages for larger projects. The article gives an example of four loosely related application concepts: Ninjas, Plants, Pirates and Zombies. The article outlines a way to structure them outside of the default folder convention by organizing files into folders by feature or area of responsibility.
这篇关于为什么 Razor Pages 是在 Asp.net Core 中创建 Web UI 的推荐方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!