I use this code in ASP.NET MVC 2 preview 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);
}
When I use a valid URL argument, such as "/ Comment / List / 22638", I get an error message:
The parameter dictionary contains an invalid entry for the 'commentId' parameter for the "System.Web.Mvc.ActionResult List (Int64, System.Nullable 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.Nullable1 [System.Int64]" method . Parameter name: parameters
If I changed the declaration to:
public ActionResult List(long id, [DefaultValue(0)] int? commentId)
The code is working fine. Is this what I'm doing wrong, or is the problem that the reflection is too strict for Int32 vs Int64? And what can I do to fix this? Insert a long line?