The list of form controls available in the Essential Studio are as follows:
- Numeric, Currency, and Percentage Textbox.
- Autocomplete and Dropdown list.
- Mask Edit.
- Checkbox and Radio Button.
The form control value can be obtained on the post back in the following ways.
- The Request object.
- The FormCollection object.
- The Parameters.
- The Scaffolding method.
The following sections explain how to get the values on the post back in these controls. You can create the EJ form controls, and define the form method as post and also define the respective action for the form post back. This is demonstrated in the following code example.
- Getting post back value by using Request object: In the Request object approach, you can use the request object of the HttpRequestBase class. The request object has the input field values in the name or value pairs. When you submit the form, the post method is called. You have six data, those in the Name or Value pairs, so that you can access these data in a POST Action method by passing the Name as an indexer in the Request object and get values from it. The following code example shows how to get the input fields values from the Request object.
Figure 1: Post back value using Request object
- Getting post back value by using the FormCollection object: You can also get the post requested data from the FormCollection object. The FormCollection object also has requested data in the name or value collection as the Request object. To get data from the FormCollection object, you need to pass it as a parameter, and it has all the input field data that submitted on the form. The following code example shows how to get the input fields values from the Form Collection.
Figure 2: Post back value using the FormCollection object
- Getting post back value by using the Parameters: You can pass all input field names as parameters to the post action method. The parameter name and input field name should be the same. These parameters have input field values that are entered to access the input field values from these parameters. The input field takes a string value from the end user, and so, the parameter should be a string type. There is no need to define a parameter in any specific sequence. The following code example shows how to get the input fields values from the parameters.
Figure 3: Post back value using Parameters
- Getting post back value by using Scaffolding method:
Strongly-Typed HTML Helper: The control supports strongly typed HTML helpers represented by lambda expressions that have model or template passed into the View. The Extension method is used to get a value from the model. The EditorFor takes lambda as a parameter that tells the helper with element of the model to use in the typed view. This enables the better compile-time checking of the views that allow you to find errors at build-time instead of at runtime, and also enables better code intelligence support within the view templates. The following steps explain how to get the values by using the Scaffolding methods.
1. Create the model for your requirement.
2. Create an action method that renders UI on the view page, and passes an empty model to be bound to the view page.
3. Create a strong typed view based on your model.
4. Create an action method, FormPost that handles the Post request and processes the data. In the action method, you can pass a model as the parameter. That model has UI input field data.
- Select the values from the EJ form controls and post the form. You can get the selected values in the post action from the model as follows.
Figure 4: Selected values in the post action