我对ASP.NET MVC 2非常陌生,而且我正忙于使用实体模型中的数据填充下拉列表以填充<>。我怀疑我的LINQ可能是错误的,但它并没有伤害找出为什么我的代码不起作用。如何使用实体模型中的数据填充Html.DropDownListFor <>?
我设法预先填充另一个DropDownListFor <>用下面的代码:
<div class="editor-field">
<% string[] Days = new string[] { "Monday", "Wednesday", "Friday" };%>
<%--<%: Html.DropDownList("Delivery Day", new SelectList(Days)) %>--%>
<%: Html.DropDownListFor(model => model.DeliveryDay, new SelectList(Days))%>
<%: Html.ValidationMessageFor(model => model.DeliveryDay)%>
</div>
我想现在填充列表如下:
<div class="editor-field">
<% List<string> categoryList = new List<string>();
var categories = from c in Model.Category select c.Category_Category;
foreach (object cata in categories)
{
categoryList.Add(cata.ToString);
}%>
<%: Html.DropDownListFor(model => model.Category_Category,new SelectList(categoryList))%>
<%: Html.ValidationMessageFor(model => model.Category)%>
</div>
这是发生了什么:
找不到源类型为'int?'的查询模式的实现。 '选择'未找到。
我该如何解决这个问题?
谢谢。我仍然在学习如何使用MVC。感谢您指出这一点 – Eon 2012-02-24 12:48:57
我会抓这个,并找到另一个点开始 – Eon 2012-02-24 12:50:19