我正在尝试确定如何将/ News/5的路由映射到我的新闻控制器.
这是我的NewsController:
public class NewsController : BaseController
{
//
// GET: /News
public ActionResult Index(int id)
{
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的Global.asax.cs规则:
routes.MapRoute(
"News", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "News", action = "Index", id = -1 } // Parameter defaults
);
Run Code Online (Sandbox Code Playgroud)
我尝试去/ News/5但是我收到了资源未找到错误,但是当进入/ News/Index/5时它有效吗?
我尝试过,{controller}/{id}但这只是产生了同样的问题.
谢谢!