我有这个路线图(请注意topicName被忽略):
routes.MapRoute(
"Topics", // Route name
"Topic/{topicName}/{action}",
new { controller = "Topic", action = "AddQuestion" });
我希望它默认映射到此Url:
http://localhost:51421/Topic/SomeName/AddQuestion?topicId=1(或者,如果不可能,请访问此网址:http://localhost:51421/Topic/SomeName/AddQuestion/topicId/1)
(应调用此操作:
public ActionResult AddQuestion(int topicId)
{
return View();
}
)
但无论哪种方式,我都需要在网址中提供所有这些数据
这样做的正确方法是什么?
答案 0 :(得分:1)
您可以添加默认路线:
routes.MapRoute(
"Topics",
"Topic/{topicName}/{action}/{topicId}",
new { controller = "Topic", action = "AddQuestion", topicId = "1" }
);
routes.MapRoute(
"Default",
"{controller}/{action}/{topicId}",
new { controller = "Topic", action = "AddQuestion", topicId = "1" }
);