我们决定在Controllers文件夹中使用子文件夹。我们所有的控制器都按照他们应该的方式工作,但由于某种原因,当我们添加{id}
时,它不会进入Controller方法路线:
routes.MapRoute(
name: "Maintenance",
url: "Maintenance/{controller}/{action}/{id}",
defaults: new { controller = "TargetAudience", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "IstPhenix.Controllers.Maintenance" }
);
这匹配网址 /维护/分类/索引
但每当我们添加{id}之类的/ Maintenance / Category / Edit / 123456789时,无法找到Controller方法
CategoryController.cs:
[ClaimsAuthorize(PhenixPermissions = "ConsultCategory")]
public ActionResult Edit(int id)
{
ViewBag.CategoryId = id;
return View("~/Views/Maintenance/Category/Edit.cshtml", id);
}
[ClaimsAuthorize(PhenixPermissions = "ConsultCategory")]
public ActionResult Index()
{
return View("~/Views/Maintenance/Category/Index.cshtml");
}
有用的是我们在RouteConfig的末尾也有一个默认路由:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "IstPhenix.Controllers.Enduser", "IstPhenix.Controllers.Maintenance", "IstPhenix.Controllers.Security" }
);
当我们省略子文件夹时,以下URL工作:
当我有一个子文件夹和一个id时,知道为什么URL与路由不匹配?
我缺少什么?
TNX!
答案 0 :(得分:0)
如果您添加了[Route("Maintenance/Category/Edit/{id}")]
[ClaimsAuthorize(PhenixPermissions = "ConsultCategory")]
public ActionResult Edit(int id)
{
ViewBag.CategoryId = id;
return View("~/Views/Maintenance/Category/Edit.cshtml", id);
}
属性
{{1}}
这将明确地给出行动路线。