通过 ASP.NET MVC Razor 视图使用 Razor 的 ASP.NET 网页

发布于 2024-11-25 02:59:36 字数 432 浏览 0 评论 0 原文

在查看带有 ASP.NET 网页的 Razor 视图引擎的最新版本时,它看起来不错,因为它具有完整的 Razor 支持。那么有人可以给我一个理由,为什么我可能想要选择带有 Razor 视图引擎的 ASP.NET 网页而不是传统的 Web 表单,或其在 ASP.NET MVC 中的 Razor 视图引擎伴侣?

对于每个网页,我指的是 VS 2010 SP 1 中提供的新网站框架: http://www.asp.net/webmatrix/tutorials/2-introduction-to-asp-net-web-programming-using-the-razor-syntax

谢谢。

In looking at the latest release of the Razor view engine with ASP.NET web pages, it looks nice because it has the full Razor support. So can someone give me a reasoning why I might want to choose ASP.NET Web Pages with the Razor view engine over traditional web forms, or its Razor view engine companion in ASP.NET MVC?

Per web pages, I'm speaking of this new web site framework available with VS 2010 SP 1: http://www.asp.net/webmatrix/tutorials/2-introduction-to-asp-net-web-programming-using-the-razor-syntax

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

勿挽旧人 2024-12-02 02:59:36

razor 中的标记更具可读性。当您的产品已经使用 Web 表单视图引擎时,您可以在过渡到 razor 视图时与其并行运行 razor,这在中型到大型项目中可能需要大量工作。请记住,在此过渡期间,部分可以是 Razor 表单或 Web 表单,但视图及其使用的母版页必须使用相同的引擎。

The markup in razor is much more readable. When you have a product that already uses the web forms view engine, you can run razor side by side with it while you transition to razor views, which can be a lot of work in medium to larger sized projects. Keep in mind that during this transition, partials may be either razor or web forms, but a view and the master page it uses must use the same engine.

雾里花 2024-12-02 02:59:36

[已修改以回答标题中提出的问题]

作为一名经验丰富的开发人员,当您想要快速完成某件事(例如 POC),或者如果您想教某人如何开始使用时,您会使用网页框架也许是 ASP.NET。

您在这里问两个单独的问题:MVC 中的 Web 表单视图引擎与 Razor View Engine,以及网页框架与 Web 表单框架。

正如其他人所说,第一个决定将取决于偏好。双方都不做对方不做的事情。这有点像 C# 或 VB 之争。

Web Pages 框架旨在为初学者提供比 Web Forms 或 MVC 更容易的“入门”方式。它可以被认为是对更简单的经典 ASP 框架的一个非常迟来的替代品,并且在这方面它与 PHP 竞争。如果您需要分离、可测试性等,您应该考虑 MVC 框架。网页框架在企业开发方法方面根本没有提供太多东西。习惯了 Web 表单,您不太可能从网页中获得任何东西。分离要困难得多。它不鼓励分层代码或测试。没有服务器控件或代码隐藏文件。而且网页仅提供网站部署(首次运行时编译),而不提供可以预编译的 Web 应用程序。

Razor 本身是为网页框架开发的。 MVC 喜欢它并将其用作新的视图引擎选项。但本质上,您现在可以选择三种 ASP.NET 框架:网页、Web 窗体和 MVC。

[Modified to answer the question posed in the title]

As an experienced developer, you would use the Web Pages framework when you want to get something done quickly (POC, for example), or if you want to teach someone how to get started with ASP.NET, perhaps.

You are asking two separate questions here: Web Forms View Engine vs Razor View Engine in MVC, and Web Pages Framework vs Web Forms Framework.

As others have said the first decision will be down to preference. Neither does anything that the other doesn't. It's a bit like the C# or VB debate.

The Web Pages framework is intended to provide an easier "in" for beginners than Web Forms or MVC. It can be considered a very belated replacement for the much easier classic ASP framework and it competes with PHP in that respect. If you need separation, testability and so on you should look to the MVC framework. The Web Pages framework doesn't offer very much at all in terms of enterprise development approaches.are used to Web Forms you are unlikely to gain anything from Web Pages. Separation is a lot more difficult. It doesn't encourage layering of code or testing. No server controls or code-behind files. And Web Pages only offers the Web Site deployment (compile on first run) as opposed to the Web Application which can be pre-compiled.

Razor itself was developed for the Web Pages framework. MVC liked it and leveraged it as a new view engine option. But essentially, you have three ASP.NET frameworks to choose from now: Web Pages, Web Forms and MVC.

空‖城人不在 2024-12-02 02:59:36

选择 Razor 的主要原因:

  • 简洁 - 页面的 HTML 结构很明显,并且没有大量的 <%%> 。 (我喜欢干净的 HTML。它让我的强迫症发痒......)
  • 流畅 - 服务器端代码和 HTML 之间的简单转换,无需强制您显式上下文切换。

The main reasons to choose Razor:

  • Terse - The HTML structure of your page is obvious, and doesn't have lots of <% and %> everywhere. (I like clean HTML. It tickles my OCD...)
  • Fluent - Simple transitions between server-side code and HTML without forcing you to explicitly context-switch.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文