Why does ASP.NET MVC 2 and 3 have gridview in toolbox?
Its pretty simple to create a gridview like object with a strongly-typed view; it 开发者_如何转开发pretty much does it for you. I can also use a foreach and create the HTML dynamically. Same diff. (The process of getting that data from the controller to the view is still magical to me).
AFAIK, MVC doesn't support viewstate. MVC doesn't have a way to reference and set GridView1.Datasource = SomeDataSource; in the Controller either.
So why is Gridview available in the toolbox when I can't set the datasource? Is the gridview useable? Is anything in the toolbox useable (outside standard HTML)?
Because if you use WebForms views, visual studio is detecting the .aspx/.ascx files.
Generally speaking nothing in the toolbox is usable for ASP.NET MVC. At least not usable in the sense that it was in ASP.NET Classic. This is just a remnant of the fact that ASP.NET MVC is built on top of ASP.NET Classic and Visual Studio's designers were created before MVC existed.
The book "ASP.NET MVC in Action" has a chapter that talks about using classic ASP.NET controls in MVC. The general take away from that chapter (at least in my opinion) is don't bother. The ones that are still usable are neutered and don't really provide any real benefit. MVC just wasn't designed with ASP.NET controls in mind (which IMO, is a great thing).
精彩评论