1

これはエラーレポートです:

パラメータディクショナリには、'Grid.Controllers.GridController'のメソッド'System.Web.Mvc.ActionResult Delete(Int32)'のnull許容型ではないタイプ'System.Int32'のパラメータ'id'のnullエントリが含まれています。オプションパラメータは、参照型またはnull許容型であるか、オプションパラメータとして宣言されている必要があります。パラメータ名:パラメータ

これが私のコードです:

public ActionResult Edit(int ProductId)
    {
        using (var db = new radioEntities())
        {
            return View(db.CAT_Products.Find(ProductId));
        }
    }

私のルーティングテーブル:

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
        );

    }

私のアクションリンク:

@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ })
4

1 に答える 1

5

idRouteTable(global.asax.cs)にが存在する場合は、パラメーターに同じ名前を使用する必要があります。

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

ActionLinkを編集(修正)することになっています:

//@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ })
@Html.ActionLink("Edit", "Edit", new { id=item.YourKey })  // depends on your Model and other code
于 2012-07-11T21:27:03.650 に答える