4

Possible Duplicate:
Difference between DropDownlist or DropDownListFor Html helper

I'm new in asp.net mvc and .net. In general my programming background in PHP.

What is the difference between DropDownList and DropDownListFor? Why the For ?

Where I can find a definition for every one of this helpers and an example to understand how to use it?

Community
  • 1
  • 1
amar
  • 49
  • 1
  • 3

3 Answers3

3

Basic difference includes:

DropdownList                              DropDownListFor
- weakly typed(runtime time checking    -strongly typed(compile time checking)
- support since mvc 1                    -supports from mvc 2
-do not support lambda expression to     -supports
     specify id/name of element         
- need to hardcode the id/name           -simply specifying via viewmodel with the help of lambda expression            
  of element                           
Akash KC
  • 16,057
  • 6
  • 39
  • 59
0

You should researc strongly typed Html Helpers.

This is an example of them : http://weblogs.asp.net/scottgu/archive/2010/01/10/asp-net-mvc-2-strongly-typed-html-helpers.aspx

AliRıza Adıyahşi
  • 15,658
  • 24
  • 115
  • 197
0

In short lay-mans terms the Html Helpers with "For" at the end expect you to pass a model/viewmodel - in essence mvc will do the plumbing, naming and repopulating of the model for you.

The non-For helpers of the same name are for when you want to construct the tag using declarative syntax in an ad-hoc (non model related fashion) i.e. you're going to type the id/name of the control as a parameter + other info directly into the helper method params and you are taking responsibility for providing the info and finding the values again when a post back occurs.

Luke Baughan
  • 4,658
  • 3
  • 31
  • 54