何时使用 ASP.NET MVC 与 ASP.NET Web 窗体? [英] When to use ASP.NET MVC vs. ASP.NET Web Forms?

查看:30
本文介绍了何时使用 ASP.NET MVC 与 ASP.NET Web 窗体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于 ASP.NET MVC 的常见问题之一是为什么要在 ASP.NET Web 窗体上使用它?答案通常包括 ViewState 和干净的 URL 等.最后,您会发现关于使用正确的工具进行工作并且它们用于不同的目的的简介.但是,我相信我从未见过这些目的是什么.那么,您什么时候会选择 ASP.NET MVC 而不是 ASP.NET Web Forms,或者是 ASP.NET Web Forms 而不是 ASP.NET MVC?

One of the common questions asked regarding ASP.NET MVC is why should you use it over ASP.NET Web Forms? The answer generally includes ViewState and clean URLs, amongst others. Towards the end you'll find a blurb about using the right tool for the job and that they serve different purposes. However, I don't believe I've ever seen what those purposes are. So, when would you actually choose ASP.NET MVC over ASP.NET Web Forms, or ASP.NET Web Forms over ASP.NET MVC?

推荐答案

您不要选择 ASP.Net MVC 而不是 ASP.Net,因为 ASP.Net MVC 仍然是 ASP.Net.您确实选择了 ASP.Net MVC 或 ASP.Net Web Forms,这样做有很多很好的理由:

You don't choose ASP.Net MVC over ASP.Net, because ASP.Net MVC still is ASP.Net. You do choose ASP.Net MVC or ASP.Net Web Forms, and there are lots of good reasons to do that:

  • 更容易控制您的 HTML
  • 更容易进行单元测试
  • 很少有陷阱"

另一方面,Web 表单确实有几点对他们有利:

On the other hand, Web Forms do have a few points in their favor:

  • 轻松快速地将简单的 CRUD/业务应用组合在一起
  • 在本地 LAN 环境中难以超越 ViewState 的性能
  • 易于学习的表单范式

结果是,如果您要在企业 LAN 环境(老实说仍然是大多数 Web 开发人员)中构建业务应用程序,Web Forms 真的很棒.从这个意义上说,微软真正了解他们的市场.但是,如果您正在为公共 Internet 构建应用程序,您可能需要 MVC,以便您可以进行彻底的测试,并确保您的页面不会因不必要的 ViewState 或 JavaScript 数据而变得臃肿.

The result is that if you're building business apps in a corporate LAN environment (which honestly is still most web developers), Web Forms is really great. In that sense Microsoft really knows their market. But if you're building an app for the public internet, you might want MVC so you can test thoroughly and be sure your pages aren't bloated with unnecessary ViewState or JavaScript data.

此外,过去几年发生的变化是,即使是许多企业 Intranet 应用程序现在也需要支持家庭/远程使用,这使得 MVC 对这群人的吸引力比以往任何时候都大.

Additionally, something that has changed over the last several years is that even many corporate intranet applications now need to support home/remote use, making MVC more attractive to that crowd than it had been.

这篇关于何时使用 ASP.NET MVC 与 ASP.NET Web 窗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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