After reading Steven Sanderson's book Pro ASP.NET MVC I am convinced about the benefits of using ASP.NET MVC over webforms.
Since ASP.NET MVC is clearly inspired by Ruby on Rails and the benefits of "Convention over Configuration" it strikes me that the M in MVC is completely missing!
In my opinion, the ease of using Rails comes equally from the convention in the use 开发者_如何学Cof models. Especially when it comes to validation, since this clearly belongs to the model and not in the presentation layer!
In Rails it is so easy to write: validates_presence_of :author or even nicer validates_uniqueness_of :title
So why is there no M in ASP.NET (M)VC ?
Is your question really, "why is there no ActiveRecord in ASP.NET MVC?"
The MVC packages don't specifically incorporate any ORM technology because Microsoft's efforts in those areas have been aimed more widely, at WebForms developers, and desktop .NET software. But both LINQ to SQL and the Entity Framework clearly help to fill the "model" niche.
As far as some of the conveniences of displaying and dealing with that model in a web app, there's the new validation support in ASP.NET MVC 2, and Dynamic Data and MVC's own HTML helpers to help display things.
You're right that the emphasis in ASP.NET MVC is on the implementation of the View and the Controller - this is because those were elements that were not well supported - View in particular - in ASP.NET. Model on the other hand we've had in abundance almost from the start so that is not, pragmatically, an issue that needed to be addressed.
You're also right the convention goes a long way toward making a framework useable however it also places constraints on the developer, sometimes this is good others less so.
In terms of things like validation and probably some other stuff that's convention based - MS is taking steps in that direction using annotation, it seems to me there's a lot that seems to be using a meta-data/annotation route to provide the sort of benefit you get from strong conventions in a more generic fashion.
The Model in MVC is basically left to the implementer, since there are so many ways of doing a model. MVC is focussed on the VC part, and how to do that well, but there certainly is an expectation that you'll be using an M.
I'd describe ASP.NET MVC as a tool-set that helps you implement the MVC pattern, it's not a full implementation of the pattern itself.
精彩评论