我正在使用選擇列表來傳遞文本到複選框,我想要的是將2個文本字段傳遞給複選框列表,但選擇列表沒有任何選項提供2或3個數據文本字段,我想自定義喜歡,但不能讓智能感知工作:在MVC的SelectList中添加額外的數據文本字段
public ActionResult Create()
{
IProductRepository ProductResp = new ProductRepository();
IQueryable<Object> getAllProducts = ProductResp .GetProductsSelectlist();
List<object> newList = new List<object>();
foreach (var events in getAllProducts)
newList.Add(new
{
Id = getAllProducts.Name, // I cant get .Name or DateAdded Intellisense here
Name = getAllProducts.Name + " " + getAllProducts.DateAdded
});
ViewData["events"] = new SelectList(newList.ToList(), "Id","Name");
return View();
}
ProductRepository
public IQueryable<Object> GetProductssSelectlist()
{
ApexWorldEntities entity = new ApexWorldEntities();
var query = from v in entity.Products
where v.Date > DateTime.Now
select new { ProductID = v.ID, v.Name , v.Date};
return query.OrderBy(v => v.Date);
}
你所說的是什麼意思?種類不知道你想實現什麼 – cpoDesign