【发布时间】:2014-10-03 22:53:47
【问题描述】:
我无法解决这个问题。
当前对控制器类型“ProductController”的操作“ListProducts”的请求在以下操作方法之间不明确: System.Web.Mvc.ActionResult ListProducts(System.Nullable`1[System.Int32]) 类型为 Nettbutikk.Controllers.ProductController System.Web.Mvc.ActionResult ListProducts(Int32, System.String) 类型为 Nettbutikk.Controllers.ProductController
有谁可以帮助我吗?
上下文:
public List<Product> getAll(int id, string something)
{
var db = new DatabaseContext();
List<Product> allProducts = new List<Product>();
var products = db.Products.Where(p => p.SubCategoriesId == id).ToList();
foreach (var p in products)
{
var product = new Product()
{
itemnumber = p.Id,
name = p.Name,
description = p.Description,
price = p.Price,
volum = p.Volum,
producer = p.Producers.Name,
pricePerLitre = pricePerLitre(p.Price, p.Volum),
category = p.SubCategories.Categories.Name,
subCategory = p.SubCategories.Name,
country = p.Countries.Name
};
allProducts.Add(product);
}
return allProducts;
}
控制器:
public ActionResult ListProducts(int? id)
{
var db = new DBProduct();
List<Product> listOfProducts;
listOfProducts = db.getAll(id);
return View(listOfProducts);
}
public ActionResult ListProducts(int id, string something)
{
var db = new DBProduct();
List<Product> listOfProducts;
listOfProducts = db.getAll(id,tull);
return View(listOfProducts);
}
还有观点:
<a href='@Url.Action("ListProducts", "Product", new { id = 1, tull = "" })'>sub category</a>
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-4