小编use*_*351的帖子

MVC3 Razor @ Html.DropDownListFor

我可以使用一些帮助实现@ 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)

linq razor asp.net-mvc-3

26
推荐指数
1
解决办法
7万
查看次数

标签 统计

asp.net-mvc-3 ×1

linq ×1

razor ×1