私はASP.Net MVC3アプリケーションミュージックストアに従っており、これに気付いています。ASP.Net MVC3は、idからalbumIdにパラメータの名前を変更した場合、私に例外を与えます
ここでは、ストアコントローラの詳細アクションです。
public ActionResult Details(int id)
{
var album = new Album() { Title = "Dark Side of The Moon" + id };
return View(album);
}
//View
@model MvcMusicStore.Models.Album
@{
ViewBag.Title = "Details";
}
<h2>Album Name: @Model.Title</h2>
それは私が「ID」からパラメータ名を変更しようとしたしかしとき、正常に動作する「ALBUMIDは、」私は次のエラーを取得する:
The parameters dictionary contains a null entry for parameter 'albumid' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Details(Int32)' in 'MvcMusicStore.Controllers.StoreController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters
なぜ特定の名前の変数を持ちます別の名前でこのエラーが発生しますか? MVCは変数名 "id"で何かを自動的に行いますか?
を持つべきである{コントローラ}/{アクション}/{ID}を、持っていますそのとおりです。私のglobal.asaxには次のようなものがあります。これは、albumIdをパラメータとして使用する場合は、** Store Controllerの新しいルートを作成する必要があることを意味しますか? http://pastebin.com/BPJLve07 –
はい、アクションのパラメータ名と一致するルートが必要です。 –
ありがとうございました。 :) –