【发布时间】:2011-01-09 11:37:43
【问题描述】:
我有几个页面与其他页面非常相似,但其中一个不起作用。
当我写 'http://localhost:2265/Segment/' 时,我收到烦人的错误消息“'/' 应用程序中的服务器错误。 找不到资源。”
“http://localhost:2265/User/”之类的其他页面和“http://localhost:2265/Segment/Create”也运行良好。所以段的索引是问题所在。我使用了 ASP.NET 路由调试器,在其他页面上我得到了正确的映射,但是在使用调试器时我也收到了同样的错误消息“找不到资源”。我认为这表明默认路由也没有捕获它。 .
有什么想法吗?
这是我的 MapRoute 命令。
routes.MapRoute(
"Maintenance",
"Maintenance/{action}",
new { controller = "Maintenance", action = "Index", id = "" }
);
routes.MapRoute(
"User",
"User/{action}",
new { controller = "User", action = "Index", id = "" }
);
routes.MapRoute(
"Segment",
"Segment/{action}",
new { controller = "Segment", action = "Index", id = "" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
更新:
感谢您的快速回复!
我删除了除默认路由之外的所有路由。没有解决问题,但是现在路由列表变短了。
我的控制器文件中有其他类,如下所示:
公共类 SegmentFormViewModel { } 公共类 SegmentController : 控制器 { } 公共类 SegmentFormCreateModel : 段 { }我试图将它移动到控制器内,但这也无济于事。
有没有办法调试这个问题?
更新:
这是我的控制器(没有方法的内容)
公共类 SegmentController : 控制器 { // // 获取:/段/ 公共行动结果索引() { } // // GET: /Segment/Details/5 公共 ActionResult 详细信息(Guid id) { } // // 获取:/段/创建 公共动作结果创建() { } // // 发布:/段/创建 [AcceptVerbs(HttpVerbs.Post)] 公共 ActionResult 创建(FormCollection 集合) { } // // GET: /Segment/Edit/5 公共 ActionResult 编辑(int id) { } // // POST: /Segment/Edit/5 [AcceptVerbs(HttpVerbs.Post)] 公共 ActionResult 编辑(int id,FormCollection 集合) { } }【问题讨论】:
-
你真的不需要这三个路线。默认路由将处理所有这些。此外,我刚刚在一个从头开始创建的 ASP.NET MVC 应用程序中测试了您的路由,它工作得非常好。所以我猜还有其他原因导致您出现问题。
标签: asp.net-mvc model-view-controller routing url-routing