MVC3 使用参数路由到特定控制器
我正在尝试使其成为可能,因此如果有人尝试访问 /content,他们将被发送到特定的控制器(在本例中为内容,然后 url 中的以下详细信息作为参数传递。url
是 http: //localhost:51118/content/1/7/test.html
我已经尝试过:
routes.MapRoute("content", "content", new { controller = "Content", action = "Index", id = UrlParameter.Optional });
我试图集成一个cms,这就是为什么url是这样的
编辑:
public class ContentController : Controller
{
public ActionResult Index()
{
var model = new Content();
return View(model);
}
}
I am trying to make it possible so if someone tryes to go to /content they are sent to a specfic controller (in this case content and then the following details after in the url are passed as parameters.
the url is http://localhost:51118/content/1/7/test.html
i have tried:
routes.MapRoute("content", "content", new { controller = "Content", action = "Index", id = UrlParameter.Optional });
im trying to integrate a cms thats why the url is what it is
EDIT:
public class ContentController : Controller
{
public ActionResult Index()
{
var model = new Content();
return View(model);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的路线不正确。仅当您访问
http://localhost:51118/content
url 时,您才会被路由到内容控制器。如果您想指定更多参数,您应该在路线中添加更多部分。routes.MapRoute("content", "content/{id1}/{id2}/{content}", new {controller = "Content", action = "Index"});
Your route is not correct. You will get routed to the Content controller only when you will access the
http://localhost:51118/content
url. If you want to specify more paramateres you should add more sections to your route.routes.MapRoute("content", "content/{id1}/{id2}/{content}", new { controller = "Content", action = "Index"});