我已添加后续操作以获取产品accroding cat.id.错误“Int32 ToInt32(System.String)'
[HttpPost]
public ActionResult OnlineHome(string CategoryId)
{
OnlineDataModel dm = new OnlineDataModel();
dm.CatagoryData = new List<category>();
dm.ProductData = new List<product>();
dm.CatagoryData = db.categories.ToList();
//dm.ProductData = (from p in db.products where p.CategoryID == Convert.ToInt32(CategoryId) select p).ToList() ;
var data= db.products.Where(d => d.CategoryID == Convert.ToInt32(CategoryId)).ToList();
return View(dm);
}
我正在以下错误
LINQ实体无法识别方法“的Int32 ToInt32(System.String)”方法,和>这种方法不能被翻译成表达商店。
需要针对此问题的解决方案。
你试过Int32.Parse()吗? – helb 2014-10-20 06:44:32
将该值转换为int,然后将该值传递给表达式。但是,为什么不只是使用参数'int'而不是那个字符串,所以你不需要做任何转换('DefaultModelBiner'会为你做) – 2014-10-20 06:45:47
谢谢stephen的帮助。有用。如果我将它转换为表达式中的int32,它为什么不起作用。 – mayurb 2014-10-20 06:59:10