为什么推荐使用Razor Pages在Asp.net Core 2.0中创建Web UI? [英] Why is Razor Pages the recommended approach to create a Web UI in Asp.net Core 2.0?

查看:308
本文介绍了为什么推荐使用Razor Pages在Asp.net Core 2.0中创建Web UI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

学习新事物需要投入时间,空间和精力.我目前正在学习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 2.0创建Web UI的推荐方法.

Razor Pages is the recommended approach to create a Web UI with ASP.NET Core 2.0.

此信息使我感到困惑,因为我决定是否必须停止学习Asp.net Core MVC并开始学习Asp.net Core Razor页面.

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 2.0中创建Web UI?

欢迎任何方向.

推荐答案

Razor页面针对基于页面的工作流程进行了优化,并且在这些情况下可以使用的移动部件比传统MVC模型少.这是因为您不需要像通常那样处理Controllers,Actions,Routes,ViewModels和Views.相反,您的路由是基于约定的,并且PageModel可以同时用作Controller,Action和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-带有剃须刀页面的更简单的ASP.NET MVC应用,由史蒂夫·史密斯在2017年9月发布的MSDN文章 a>:

From ASP.NET Core - Simpler ASP.NET MVC Apps with Razor Pages, a Sept. 2017 MSDN article by Steve Smith:

[剃刀页]提供

[Razor Pages] provide

  • 一种在ASP.NET Core应用程序中组织代码的更简单方法,使实现逻辑和视图模型更接近于视图实现代码.
  • 它们还提供了一种更简单的方法来开始开发ASP.NET Core应用程序,

该文章详细介绍了为什么要在基于页面的工作流程上使用基于MVC的Razor页面.显然,对于API,您仍然需要使用Controllers.

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 2.0中创建Web UI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆