我有3个动作;类别,标记和搜索具有相同类型的路由签名,但路由以不同的值开头。
现在只有类别可以正常工作,而其他两个则不能。
搜索操作显示:URL和页面加载中的localhost/search?s=SOMEWORD
。
但是标签操作给我一个错误:The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
我希望我的路线为localhost/{action}/{someWord}
,但不能。
控制器操作:
public ActionResult Category(string category, int p = 1)
{
//some caculations
return View("List", viewModel);
}
public ActionResult Tag(string tag, int p = 1)
{
//some caculations
return View("List", viewModel);
}
public ActionResult Search(string s, int p = 1)
{
//some caculations
return View("List", viewModel);
}
RouteConfig:
routes.MapRoute(
"Category",
"Category/{category}",
new { controller = "Blog", action = "Category" }
);
routes.MapRoute(
"Tag",
"Tag/{tag}",
new { controller = "Blog", action = "Tag" }
);
routes.MapRoute(
"Search",
"Search/{s}",
new { controller = "Blog", action = "Search" }
);