【发布时间】:2010-02-04 05:36:25
【问题描述】:
我真的要疯了。
这是我的 Global.asax 中的内容
routes.MapRoute("BlogDetails", "Blogs/{id}/{title}", new { controller = "Blogs", action = "Details", id = "" });
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
这是我仅有的两条路线。
当我尝试访问时
http://mysite/Blogs/Edit/1不起作用我收到此错误
参数字典包含“mysite.Controllers.BlogsController”中方法“System.Web.Mvc.ActionResult Details(Int32)”的不可为空类型“System.Int32”的参数“id”的空条目。可选参数必须是引用类型、可空类型或声明为可选参数。
为什么会一直这样?
谢谢
我还应该添加我的控制器代码,如下所示
//
// GET: /Blogs/Edit/5
[Authorize]
public ActionResult Edit(int id)
{
// do a bunch of stuff and return something
}
【问题讨论】:
-
如果在第二条路由中删除
id的默认值会怎样? -
仍然给我同样的错误。它还破坏了网站上的所有其他链接
标签: c# asp.net-mvc model-view-controller