Could someone help me with the proper syntax?
Not sure how to write the DropDownListFor HTML helper. How would I write this with “Mouse” selected based on the Value property of 3? I’m not using a model, just trying to whip up a quick list within razor.
Thanks
var AnimalList = new List<SelectListItem>();
AnimalList.Add(new SelectListItem { Text = "Dog", Value = "1" });
AnimalList.Add(new SelectListItem { Text = "Cat", Value = "2" });
AnimalList.Add(new SelectListItem { Text = "Mouse", Value = "3" });
AnimalList.Add(new SelectListItem { Text = "Squirrel", Value = "4" });
AnimalList.Add(new SelectListItem { Text = "Fox", Value = "5" });
@Html.DropDownListFor(? , ?, ?);
You can’t use
@Html.DropDownListForwithout model. But you can use@Html.DropDownListwithout model.In controller
In view