【发布时间】:2014-02-06 21:17:04
【问题描述】:
我正在尝试将一些值添加到对象的 SelectList 数据成员中,但出现错误
public ActionResult Create()
{
var paf = new ProductAddForm();
paf.Sizes = new SelectList(m.GetProductSizes());
paf.Suppliers = new SelectList(m.GetAllSuppliersList(), "Id", "Name");
return View(paf);
}
那是我的 creat 函数,paf.Sizes / paf.Suppliers 代码不起作用。
我的 productaddform 类:
public class ProductAddForm
{
public double MSRP { get; set; }
public string Name { get; set; }
public string ProductId { get; set; }
public ICollection<SelectList> Sizes { get; set; }
public ICollection<SelectList> Suppliers { get; set; }
public string UPC { get; set; }
}
还有我在 manager.cs 中的方法
public IEnumerable<SupplierList> GetAllSuppliersList()
{
var fetchedObjects = ds.Suppliers.OrderBy(n => n.Name);
var Suppliers = new List<SupplierList>();
foreach (var item in fetchedObjects)
{
var s = new SupplierList();
s.Name = item.Name;
s.Id = item.Id;
Suppliers.Add(s);
}
return (Suppliers);
}
public List<string> GetProductSizes()
{
return new List<string>() { "Small", "Medium", "Large" };
}
怎么了?
【问题讨论】:
-
paf.suppliers 接受
ICollection<SelectList>供应商,但您输入的是单个选择列表new SelectList(m.GetAllSuppliersList(), "Id", "Name");
标签: c# asp.net asp.net-mvc asp.net-mvc-4