1
votes

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 */ })
1

1 Answers

5
votes

When there is an id in your RouteTable (global.asax.cs) then you have to use the same name for the param:

//public ActionResult Edit(int ProductId)
public ActionResult Edit(int id)

You are supposed to edit (fix) the ActionLink:

//@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ })
@Html.ActionLink("Edit", "Edit", new { id=item.YourKey })  // depends on your Model and other code