【发布时间】:2019-10-03 12:13:16
【问题描述】:
我在 MVC 应用程序中使用基于属性的路由。我的代码是 -
[RouteArea("MasterData")]
[RoutePrefix("BrandFacilityShipmentMaintenance")]
public class BrandFacilityShipmentMaintenanceController : Controller
{
[Route("Index")]
public ActionResult Index()
{
}
}
我正在尝试使用可变参数来访问网址,例如
/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 在基于传统的路由中都命中了相同的索引操作。我应该改变什么才能使它在基于属性的路由中工作。
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 代码以获得更好的清晰度
-
@MannanBahelim 发布
标签: c# .net asp.net-mvc asp.net-mvc-routing