I'm a newbie in MVC, so please help me to get out of this. I want to retrieve NameofBike
in DB. I'm using LINQ for it, but something wrong in there.
My Action
:
public ActionResult Index(int Id, string Name)
{
// Create our view model
var viewModel = BikesDB.ProductSubcategories
.Where(m => m.NameofBike == Name && m.ProductSubcategoryID == Id);
return this.View(viewModel);
}
ViewModel:
public class Bike
{
public int Id { get; set; }
public String Name { get; set; }
}
public class CategoriesIndexViewModel
{
public int NumberOfModel { get; set; }
public List<string> NameofBike { get; set; }
public List<Bike> Bikes { get; set; }
}
When debugged it throws an error like this:
The parameters dictionary contains a null entry for parameter 'Id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Index(Int32, System.String)' in 'AdventureCycle.Controllers.BikeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Here's the navigate:
<ul id="navlist">
<li>
<a href="@Url.Content("~/Bike/")">Home</a>
<ul>
<li>
<a href="@Url.Content("~/Bike/Categories/1?name=Mountain Bikes&class=image")">Mountain Bikes</a>
</li>
<li>
<a href="@Url.Content("~/Bike/Categories/2?name=Road Bikes&class=image")">Road Bikes</a>
</li>
<li>
<a href="@Url.Content("~/Bike/Categories/3?name=Touring Bikes&class=image")">Touring Bikes</a>
</li>
</ul>
</li>