0

I am trying to use the SelectExtensions.DropDownListFor method, but there are very few examples on the interweb and only one or two on stackoverflow. I can't get my drop down to work.

Here is an extract on my .cshtml:

@SelectExtensions.DropDownListFor( m => m.LegalEntity.Address.Country.SelectedCountry,
    new SelectList( Model.LegalEntity.Address.Country.Countries, 
    "CountryId", "Name",
    Model.LegalEntity.Address.Country.Countries.First().CountryId))

I have been following the format of a stackoverflow post (MVC3 DropDownListFor - a simple example?), but I can't get it to work. Both IntelliSense and the compiler complain that the LegalEntity does not exist in the model, but it does. IntelliSense can't offer any suggestions for the Func in the first line.

What am I doing wrong??

Mark

Community
  • 1
  • 1
serlingpa
  • 12,024
  • 24
  • 80
  • 130

1 Answers1

1

DropDownListFor is an extension method, SelectExtensions is a static class.

you should use

@Html.DropDownListFor(m => m...)

Where Html will be the this HtmlHelper<>... first parameter of the extension method.

If you really want to keep your formulation, you should have

@SelectExtensions.DropDownListFor(Html, m => m.LegalEntity....)

But with extension methods, you don't need the static class name, but you can use

<the first parameter with the this keyword of the method>.TheMethod(secondParameter, thirdParameter, etc.)

Raphaël Althaus
  • 59,727
  • 6
  • 96
  • 122