【发布时间】:2009-08-07 06:55:09
【问题描述】:
我在 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);
}
当我使用有效的 URL 参数(例如“/Comment/List/22638”)时,我收到错误:
参数字典包含一个 参数输入无效 方法的“commentId” 'System.Web.Mvc.ActionResult 列表(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]'。 参数名称:参数
如果我将声明更改为:
public ActionResult List(long id, [DefaultValue(0)] int? commentId)
代码运行良好。这是我做错了什么,还是反射对于 Int32 和 Int64 类型过于严格的问题?我能做些什么来解决它?将 long 转换为字符串?
【问题讨论】:
-
这在 MVC1 中对我有用。你能重现 MVC1 中的错误吗?
-
还没有尝试过 MVC 1 .. 因为这是一个新项目,我正在“展望未来”并且非常享受新模板的支持,我不想回到 MVC 1 . 这是让 MVC 对我更有吸引力的版本 :)
-
我的意思是,我还没有在 MVC 1 中测试过这个。
标签: asp.net-mvc dictionary parameters preview