This is the error report:
The parameters dictionary contains a null entry for parameter ‘id’ of
non-nullable type ‘System.Int32’ for method
‘System.Web.Mvc.ActionResult Delete(Int32)’ in
‘Grid.Controllers.GridController’. An optional parameter must be a
reference type, a nullable type, or be declared as an optional
parameter. Parameter name: parameters
and this is my code:
public ActionResult Edit(int ProductId)
{
using (var db = new radioEntities())
{
return View(db.CAT_Products.Find(ProductId));
}
}
My routetable:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Grid", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
My actionlink:
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ })
When there is an
idin your RouteTable (global.asax.cs) then you have to use the same name for the param:You are supposed to edit (fix) the ActionLink: