【发布时间】:2012-03-09 01:49:00
【问题描述】:
我正在尝试确定如何将 /News/5 的路由映射到我的新闻控制器。
这是我的 NewsController:
public class NewsController : BaseController
{
//
// GET: /News
public ActionResult Index(int id)
{
return View();
}
}
这是我的 Global.asax.cs 规则:
routes.MapRoute(
"News", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "News", action = "Index", id = -1 } // Parameter defaults
);
我尝试转到 /News/5,但收到资源未找到错误,但是在转到 /News/Index/5 时它可以工作吗?
我只尝试过{controller}/{id},但这也产生了同样的问题。
谢谢!
【问题讨论】:
-
当您尝试
{controller}/{id}时,您是否保留了默认设置?new { controller = "News", action = "Index", id = -1 }
标签: asp.net asp.net-mvc routes asp.net-mvc-4