Ok, my drop down used to be made like so:
<select id="Level" onchange="showChoice(this.value);">
<option id="0" value="0">Pick a Level</option>
@for (int i =1; i <= Model.ExamplesCount; i++ )
{
<option id="@i" value="@i">Level @i</option>
}
</select>
because the ExamplesCount number changes per user. But I need to use the Html.ValidationMessageFor()
thing, which I can't get to work with this.
I need one of two solutions.
- Can I make
Html.ValidationMessageFor()
work with thisselect
tag?
or if not,
2.Can I use Html.DropDownListFor()
but fill it in with a similar for loop?
For example,
@Html.DropDownListFor(
m => m.Level,
new SelectList(
new List<Object> {
new {value = 0, text ="Pick a Level"},
new { value = 1, text = "Level 1"},
new { value = 2, text = "Level 2" },
new { value = 3, text = "Level 3" },
new { value = 4, text = "Level 4" },
new { value = 5, text = "Level 5" }
},
"value", "text", null))
@Html.ValidationMessageFor(model => model.Level)
The above code works, but where I am hard coding all the SelectList values, I'd like to have an for loop that does it for me.