SelectList elements= new SelectList(new [] {"10", "15", "25", "50", "100", "1000"}, "15");
IList customers = repository.GetAll();
IEnumerable selectList =
from c in customers
select new SelectListItem
{
Selected = (c.CustomerID == invoice.CustomerID),
Text = c.Name,
Value = c.CustomerID.ToString()
};
ViewData["myList"] =
new SelectList(new[] { "10", "15", "25", "50", "100", "1000" }
.Select(x => new {value = x, text = x}),
"value", "text", "15");
<%=Html.DropDownList("myList") %>
SelectList sl = new SelectList( new[]{
new SelectListItem{ Text="one", Value="1"},
new SelectListItem{ Text="two", Value="2"},
new SelectListItem{ Text="three", Value="3"}
}, "Text", "Value", "2" );
Referencias:
http://blog.wekeroad.com/blog/asp-net-mvc-dropdownlist-and-html-attributes/
No comments:
Post a Comment