return new SelectList(new[] { "Please choose an option." });
In the preceding statement, how can I add a value=string.empty for the text value above?
Thanks, rodchar
The following is what works for me, however, is there a more consise way to write this?
return new SelectList(new[] { "Please choos开发者_如何学编程e." }
.Select(a => new { value = "", text = a.ToString() }), "value", "text", "");
In General, I have been using something like this, you can customize this for your purpose (particularly the values part).
<% var values = Enumerable.Range(1,10); %> <!-- values from 1 to 10 -->
<%= Html.DropDownList("DropDownId",
values.Select(x => new SelectListItem { Text = x.ToString(), Value = x.ToString()})) %>
For your case, I think you found the answer, just wanted to share how I use it.
Thanks
精彩评论