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よりも使用しているデータアクセス技術に関連しているようですので、その件について少し詳しく説明し、質問を再投稿することをお勧めしますか? –