1
我有一个int列表插入一个对象的问题。控制器看起来像:int的插入列表
public ActionResult Edit(int productID)
{
//ProductEditViewModel pm = new ProductEditViewModel();
Product product = _pr.GetProducts().ByProductID(productID).First();
product.Categories.Load();
//ICollection<Category> allCategories = _cr.GetCategories().ToList();
List<SelectListItem> Categories = (from category in _cr.GetCategories().ToList()
join pc in product.Categories
on category.CategoryID equals pc.CategoryID into j
select
new SelectListItem
{
Selected = j.Any(),
Value = category.CategoryID.ToString(),
Text = category.Categoryname
}).ToList();
ViewData["allCategories"] = Categories;
return View("Edit", new ProductEditViewModel { Product = product });
}
//
// POST: /Products/Edit/5
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Product product, int[] CategoryID)
{
try
{
// TODO: Add update logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
如何更新/插入“product.Categories”的所有CategoryID列表?
而且我应该有别的东西而不是“int [] CategoryID”吗?
在此先感谢 /M
那是你正在使用的LINQ to SQL吗?在我看来,你的问题与你使用的数据访问技术相比,更多地与ASP.NET MVC相关,所以我建议你在这个主题上扩展一下,也许重申你的问题? – 2009-08-18 08:01:34