Fill out @ html.DropDownListFor () with the elements on Twitter. Bootstrap and C # style

I am trying to populate a drop down list of items. I am using MVC4 with twitter bootstrap style, at visual studio 2012.

The code I have for the controller is:

String[] genders =  { "Male","Female","Other"};
ViewBag.genders = new SelectList(genders);

And in my opinion:

@Html.DropDownListFor("genders", "Select a gender", new { @class = "form-control" })

However, I get the error message:

'Type arguments for the method' System.Web.Mvc.Html.SelectExtensions.DropDownListFor (System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression> System.Collections.Generic.IEnumerable, object) 'cannot be deduced from use. Try specifying the type of arguments explicitly. '

I have tried various other application forms. But basically, I would like to keep the controller as is and edit the statements in the view. But I am open to everything that people are ready to offer, to help me solve this problem.

+4
2

:

@Html.DropDownListFor(m=>m.SelectedGender, (SelectList)ViewBag.genders, "Select gender", new { @class = "form-control" })

m=>m.SelectedGender, - ( , @Html.DropDownList ).

+15

@Html.DropDownListFor lamda, .

... DropDownListFor... . , , DDL.

@Html.DropDownListFor(m=>m.Gender, (SelectList)ViewBag.genders, "Select gender", new { @class = "form-control" })

, ... @Html.DropDownList() .

@Html.DropDownList("SelectedGender", (SelectList)ViewBag.genders, "Select gender", new { @class = "form-control" })
+2

All Articles