我可以使用一些帮助实现@ Html.DropDownListFor.我的目标是按类别过滤产品列表.
此代码将显示一个列表框:
@model IEnumerable<Sample.Models.Product>
@{
List<Sample.Models.Category> list = ViewBag.Categories;
var items = new SelectList(list, "CategoryID", "CategoryName");
}
@Html.DropDownList("CategoryID", items)
Run Code Online (Sandbox Code Playgroud)
但我@Html.DropDownListFor上班有困难:
@model IEnumerable<Sample.Models.Product>
@{
List<Sample.Models.Category> list = ViewBag.Categories;
var items = new SelectList(list, "CategoryID", "CategoryName");
}
@Html.DropDownListFor(???, @items)
Run Code Online (Sandbox Code Playgroud)
我可以使用一些帮助构建Linq部分@Html.DropDownListFor.这是模型:
public class Product
{
public int ProductID { get; set; }
public string ProductName { get; set; }
public int CategoryID { get; set; }
public string QuantityPerUnit { get; set; }
public Decimal? UnitPrice { get; …Run Code Online (Sandbox Code Playgroud)