DropDownList vs DropDownListfor

Rashmi
Rashmi
Member
78 Points
24 Posts

Hi,

I am working on dropdown list. I am little confused, what should use in mvc view model binding DropDownList or DropDownListfor?

Views: 8164
Total Answered: 2
Total Marked As Answer: 0
Posted On: 05-Dec-2015 06:48

Share:   fb twitter linkedin
Answers
Priya
Priya
Member
62 Points
26 Posts
     

Hi Rashmi,

In DropDownList control name is put static while in DropDownListFor dynamic, we can change the name from the model.

Syntax:

@Html.DropDownList("EquipmentId", new SelectList(Model.Country, "Id", "Text"))
@Html.DropDownListFor( x => x.CountryID, new SelectList(Model.Country, "Id", "Text"))
Posted On: 05-Dec-2015 08:26
Rahul Maurya
Rahul M...
Moderator
1170 Points
210 Posts
     

All of the HTML XX_For Helpers are expression-based versions (lambda expression) are primarily used for pulling values from the model (they are parametrized by the current model).

Posted On: 05-Dec-2015 09:18
banner

Blog

Active User (2)

 Log In to Chat