我有 Controller 名称:District和Action名称:Incharges但我希望URL像这样(带有某些参数的操作名称)
www.example.com/district/incharges/aaa
www.example.com/district/incharges/bbb
www.example.com/district/incharges/ccc
但是,在调试teamName时,在action参数中始终将其返回为NULL。
路由
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
"DistrictDetails",
"District/Incharges/{teamName}",
new { controller = "District", action = "Incharges" }
);
Controller
但是,在调试teamName时,在action参数中始终将其返回为NULL。
public class DistrictController : Controller
{
public ActionResult Incharges(string teamName)
{
InchargePresentationVM INPVM = new InchargePresentationVM();
INPVM.InitializePath(teamName, string.Empty);
return View("", INPVM);
}
}
查看
@{
ViewBag.Title = "Index";
}
<h2>Index About</h2>
最佳答案
您必须先声明的特定路线
routes.MapRoute(
"DistrictDetails",
"District/Incharges/{teamName}",
new { controller = "District", action = "Incharges", id = UrlParameter.Optional }
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
););