We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to return the model value of DropDownList to the controller using scaffolding method?

Description

Strongly-Typed HTML Helper: The DropDownList 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. 

Solution

The DropDownListFor 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.

C#

 

  1. Create an action method that renders UI on the view page, and passes the model to be bound to the view page.

     C#

 

  1. Create a strong typed view based on your model.

C#

 

 

  1. 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.

C#

 

  1. 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.

 

 

 

Article ID: Published Date: Last Revised Date: Platform: Control:
7022 07/29/2016 07/29/2016 ASP.NET MVC DropDownList
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.