Vel*_*elu 7 asp.net-mvc asp.net-mvc-3 asp.net-mvc-4
我有控制器名称:区域和操作名称: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" }
);
Run Code Online (Sandbox Code Playgroud)
调节器
但是,调试teamName时总是在action参数中返回NULL.
public class DistrictController : Controller
{
public ActionResult Incharges(string teamName)
{
InchargePresentationVM INPVM = new InchargePresentationVM();
INPVM.InitializePath(teamName, string.Empty);
return View("", INPVM);
}
}
Run Code Online (Sandbox Code Playgroud)
视图
@{
ViewBag.Title = "Index";
}
<h2>Index About</h2>
Run Code Online (Sandbox Code Playgroud)
Ily*_*lya 17
具体路线你必须申报第一个
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 }
););
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14832 次 |
最近记录: |