我有控制器名称:区域和操作名称:Incharges但我希望URL是这样的(带有一些paremeter的动作名称)
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" } );
调节器
但是,调试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",action = "Incharges",id = UrlParameter.Optional } routes.MapRoute( name: "Default",id = UrlParameter.Optional } ););