3

我相信 MVC 支持基于类型和/或分辨率的浏览器嗅探和切换视图。在我们团队在使用 Webforms 或 MVC(4.0 版)开始新项目之间的持续争论中,Webforms 是否有这种支持?如果不是,我们是否只使用 css 媒体标签和 Twitter Bootstrapper 来提供灵活的布局?我们的一些应用程序是针对固定显示器的,但其他部分应该是平板电脑和手机友好的。我想知道如果我们使用 WebForms 以后这是否会更难。

此外,MVC 让您可以完全控制标记,因此对 jQuery 非常友好。鉴于我们无法使用服务器控件来控制标记,WebForms jQuery 是否友好?

像这样的任何其他问题我没有想到可能会有所作为?

4

1 回答 1

2

Newer versions of ASP.NET webforms (especially 4.0 onwards) are much more "friendly" towards serving up content based upon the specific device that's accessing the website, as well as having improvements that allow much "cleaner" output of the rendered mark-up that's generated by server-side controls.

This is also true of MVC of course, but don't forget that ASP.NET MVC is written on top of the same ASP.NET runtime that ASP.NET Webforms uses. Because of this, lots of the benefits that are originally exposed via MVC are now available to Webforms, too.

There is a very good whitepaper on Microsoft's ASP.NET site, How To: Add Mobile Pages to Your ASP.NET Web Forms / MVC Application, that explains in detail how features such as Request.Browser.IsMobileDevice & Request.Browser.ScreenPixelsWidth (both fundamental features of the underlying ASP.NET runtime therefore equally applicable to both WebForms & MVC) can be used to detect the capabilities of the device currently accessing the website. If you require very detailed information about the device, then you'll need to integrate something like WURFL into your website irrespective of whether you're using WebForms or MVC. Moreover, if you require very specific layouts on devices with different form-factors and aspect ratios, you'll need to provide pages (either MVC views or ASP.NET webpages) that are specifically designed and targeted to those devices either way.

With regard to the ability to cleanly use jQuery with ASP.NET WebForms, since ASP.NET WebForms 4.0, you have the ability to tightly control the ClientID values that are applied to the DOM elements in the rendered markup. There's a new property called, ClientIDMode that makes it very easy to ensure you have a known value for an element's ID, thus enabling a much easier use of jQuery. Setting the value of the ClientIDMode to either of the static or predictable values will give you ID values to your elements that are much easier to work with in jQuery. One thing to be aware of here, though, is that since the ASP.NET Runtime is still generating the HTML elements and assigning values to their ID's, you can still end up with duplicated ID values, especially when using compound controls (i.e. controls such as the GridView control that has it's own ID value, but is itself made up of many constituent controls/elements - each with their own ID's of course).

Overall, the choice between ASP.NET WebForms and ASP.NET MVC will probably come down to what you're most comfortable and productive with. Personally, I would use MVC as I like the additional benefits of it's testability and better separation of concerns over WebForms, although it must be said that ASP.NET WebForms version 4.0+ is more powerful and much improved over the previous versions - you can even have MVC-style routing, extensionless URL's and more with ASP.NET WebForms nowadays.

于 2012-12-17T16:18:00.173 回答