ASP.NET MVC 2 プレビュー 1 でこのコードを使用しています。
public ActionResult List(long id, [DefaultValue(0)] long? commentId)
{
var model = UserComment.ForRefId(id);
PageTitle = string.Format("Comments for '{0}'",
SetCommentThread(id).Subject);
ViewData[MvcApplication.SAnchor] = commentId;
return View("List", model);
}
「/Comment/List/22638」などの有効な URL 引数を使用すると、次のエラーが発生します。
パラメータ ディクショナリに、メソッド 'System.Web.Mvc.ActionResult List(Int64, System.Nullable 1[System.Int64]') のパラメータ 'commentId' の無効なエントリが含まれています
1[System.Int64])' in 'ThreadsMVC.Controllers.CommentController'. The dictionary contains a value of type 'System.Int32', but the parameter requires a value of type 'System.Nullable
。パラメータ名: パラメータ
宣言を次のように変更すると:
public ActionResult List(long id, [DefaultValue(0)] int? commentId)
コードは正常に実行されます。これは私が間違っていることですか、それとも Int32 と Int64 に対してリフレクションの型が厳密すぎるという問題ですか? そして、それを修正するにはどうすればよいですか? long を文字列としてキャストしますか?