I am new to asp.net MVC. I have two tables named as Category and Product. Product table has foreign key which CategoryID. I am able to display category on a page. Lets take one example. I have two categories named Mobiles and Computers. When I click in Computer, I would like to display products related to Computer Category.
I have attached codes. Kindly, help me with this.
public ActionResult ProductList(int? id)
if (id == null)
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
Product product = db.Products.Find(id);
if (product == null)
You are trying to return a single result with IEnumerable model, that's the reason you are getting this error. Try this approach:
var products = db.Products.Where(pr => pr.Id == id) .Take(1) .ToList(); return View(products);