In ASP.NET MVC, do I use the "regular" controls from the toolbox and assign data to them like I did with webforms? Can I use the gridview, for example?
Thank you.
EDIT: The answer appears to be no. So what do you use? Are there any drag and drop controls in Visual Studio like the webform controls?
For the most part, use of MVC is explicitly not a drag/drop affair. There isn't a level of auto-wiring data-bound controls either. The purpose within MVC's structure is to give more direct control over the markup. There are some helper methods that can be used with rendering Form controls. MVC is a very different development model server-side. NOTE, you can combine ASP.Net with MVC into a hybrid project.
I would suggest that you need to be very comfortable with HMTL markup, and how HTTP + HTML communication works in order to be successful with an MVC project. The use of javascript is also very explicit. MVC is very nice with regards to a separation of concerns from back end, and front end in web based applications. This makes it easier to design and test the back-end logic, in comparison to the front-end rendering. It is a framework for web developers (web based applications are the first concern), not a developer framework for a web front end (ASP.Net controls based).
Some controls from the WebForms toolbox will work just fine (although I believe the
GridView
is not one of them...) in ASP.NET MVC. The keys are that you can't use controls that rely on either__doPostback()
javascript function), orHowever, I'm not sure that you really want to use those controls. One of the main ideas with ASP.NET MVC is to regain control over your html markup - something you don't really have with a
GridView
. If you want to have a reusable grid layout to present data, I recommend using aPartialView
or anExtension Method
to theHtmlHelper
class, depending on the complexity of your data.No, any control that uses the
__doPostBack
JavaScript function to trigger postbacks will not work. Also there is no concept ofViewState
in ASP.NET MVC so any control that relies on ViewState or ControlState will not work either.The idea behind ASP.NET MVC is to take a different approach than the heavier WebForms model (and most of its controls).
I believe you can use any control that does not rely on postback functionality.
The answer is Yes and No. Preferrably No.
This is what the community fears, an aggressive blending of asp.net and MVC into an unrecognizable and unecessarily complicated kludge.
For anyone looking at MVC, I'd suggest:
So to answer your question, MVC is still new, MVC Contrib, MVC Futures and Html helpers are avaiable in the framework and all over the web. Keep surfing and keep your own library of tweaks then post them so others can find and improve on them and vice versa. MVC can be the change the .net community has been waiting for, let's not go back to drag and drop so quickly.
Good luck!
You cannot use WebForms Controls in ASP.NET MVC directly.
But you can wrap any control inside an HTML helper.
Example a GridView:
But this will not function as a WebForm GridView.
It is just for rendering the HTML.