开发者

need a value attribute

开发者 https://www.devze.com 2022-12-11 08:13 出处:网络
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?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消