Update: This KB article has been deprecated from version 2010 vol1. Take a look at a new demo of our native ASP.NET MVC Extensions: http://mvc.devexpress.com/.
ASP.NET web controls are ready-to-use functional blocks which help developers build web applications with ease. To add a large amount of functionality in your ASP.NET web project, usually, it's sufficient to drop a control onto a form.
Since ASP.NET MVC does not support the same model as ASP.NET WebForms, there might be a question whether using WebForms controls is still supported when developing an ASP.NET MVC web application?
Yes! You can use DevExpress ASP.NET controls in ASP.NET MVC.
Because the default view engine is based on WebForms (in ASP.NET MVC). Therefore, the runtime environment is largely the same. Including the availability of the standard page lifecycle and classic page and control-specific events (such as Init, Load, PreRender, etc). This allows server controls to be used in ASP.NET MVC as elements of a View - they are in charge of the display of information and interaction with end-users.
However, this approach does have some unique caveats. For example, web controls can only be contained within Views. But, the main logic of MVC web applications is implemented within Controllers (which don't have any UI controls and don't know about them). How then is interaction between these two application layers - Controllers and Views, implemented?
To shed light on this problem, we have created a demo application that uses DevExpress web controls and illustrates how they can be used within an ASP.NET MVC application's environment. You can download both the C# and VB.NET sources of the demo in the Attachments section below.
Update: This demo has been deprecated from version 2010 vol1. Take a look at a new demo of our native ASP.NET MVC Extensions that can be accessed at: http://mvc.devexpress.com/.
In this demo, we divide requests to the server into two groups:
1. Requests that don't relate to the application's business logic:
For example, these are requests sent by an ASPxGridView control to process its own sorting or filtering operations. On the server, processing requests of this type is transparent for a Controller: however, within a View, the web control that initiated the request (such as the ASPxGridView) processes the request by itself. Usually in ASP.NET WebForms, the request processing is performed using the PostBacks or Callbacks.
In the demo application, the view page located at Views\Mail\List.aspx contains an ASPxGridView control. This ASPxGridView sends callback requests to the server for sorting and filtering operations. These requests are routed to the same action which is used to display the grid (MailController.List). The processing of the initiated sorting or filtering grid operation is delegated to the grid control.
2. Requests that implement the functionality of the application:
These requests should target particular Actions. We use a specific FORM element for these requests (see the FORM with ID "helperForm" in the Views\Shared\Site.master page). Thanks to the rich and powerful client-side API of DevExpress web controls, we can collect the information required for the initiated action on the client side, place this information into the form's hidden input, and perform a submit operation, targeting the required action.
The Mail\List view uses DevExpress' combo box and button to move email messages to other folders. To execute a move operation, the following information is required: a list of identifiers (that identify the selected emails) and the name of a folder (to which the emails should be moved). Using the client-side API, the identifier list is obtained from the ASPxGridView, and the folder name is taken from the combo box editor ('FoldersCombo'). The collected data is packed up into a JSON string, and is submitted to the required navigation location (in particular, the URL is /mail/move/).
On the server side, the data passed from the client is decoded, and a Controller receives all the information it requires to perform a business operation.
Proceeding with the previous example, a generated request is routed to the action: MailController.Move. Using the GetQuery method, we obtain a dictionary that contains a list of email identifiers and the target folder. As a result, a Controller has all the required information to perform the action.