[英]Url not hitting MVC attribute based routing controller
我在MVC应用程序中使用基于属性的路由。 我的代码是-
[RouteArea("MasterData")]
[RoutePrefix("BrandFacilityShipmentMaintenance")]
public class BrandFacilityShipmentMaintenanceController : Controller
{
[Route("Index")]
public ActionResult Index()
{
}
}
我正在尝试使用类似variabale参数的网址
/MasterData/BrandFacilityShipmentMaintenance/Index
/MasterData/BrandFacilityShipmentMaintenance/Index/1156?pid=1120
/MasterData/BrandFacilityShipmentMaintenance/Index/1156?pid=1120&fname=Brand+Facility+Shipment+Maintenanca
/MasterData/BrandFacilityShipmentMaintenance/Index/1156?pid=1120&fname=Brand+Facility+Shipment+Maintenanca&isReffered=false
但是它说找不到资源。 在基于常规的路由中,所有这些URL均击中相同的Index操作。 我应该进行哪些更改才能使其在基于属性的路由中工作。
AreaRegistration.cs-
public override void RegisterArea(AreaRegistrationContext context)
{
context.Routes.MapMvcAttributeRoutes();
context.MapRoute(
"Masterdata_default",
"Masterdata/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
您可能将基于约定的路由与属性路由相结合,并且在映射属性路由后应注册区域。
在RouteConfig.RegisterRoutes(RouteTable.Routes)
之后在Application_Start()
添加区域注册
AreaRegistration.RegisterAllAreas();
尝试在RouteArea中使用命名参数“ AreaPrefix”
[RouteArea("MasterData", AreaPrefix = "MasterData")]
它应该工作。
您也可以删除RouteArea属性,并按以下方式仅使用RoutePrefix
[RoutePrefix("MasterData/BrandFacilityShipmentMaintenance")]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.