Tôi mới dùng ASP.NET nói chung và gần đây đã gặp lỗi này mà tôi không thể tìm thấy trên web (có thể vì bản phát hành gần đây của MVC ? 6)Cách giải quyết System.InvalidOperationException sử dụng MVC 6 - Cùng mẫu
System.InvalidOperationException The following errors occurred with attribute routing information:
Lỗi 1:
Thuộc tính tuyến đường với cùng tên 'GetByIdRoute' phải có cùng mẫu: hành động: 'Appname.Web.Controllers.MemberController.GetById' - Mẫu: 'api/Member/{id: int} 'Hành động: ' Appname.Web.Controllers.PaymentController.GetById '- Mẫu: ' api/Payment/{id: int} 'Hành động: ' Appname.Web.Controllers.PlanController.GetById '- Mẫu: 'api/Kế hoạch/{id: int}'
Điều này cho phép một thợ mã để startup.cs
Line 73:
Line 74: // Add MVC to the request pipeline.
Line 75: app.UseMvc(routes =>
Line 76: {
Line 77: routes.MapRoute(
với dòng 75 nhấn mạnh
và điều này:
at Microsoft.AspNet.Mvc.ControllerActionDescriptorBuilder.Build(ApplicationModel application)
at Microsoft.AspNet.Mvc.Core.ControllerActionDescriptorProvider.GetDescriptors()
at Microsoft.AspNet.Mvc.Core.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context)
at Microsoft.AspNet.Mvc.Core.DefaultActionDescriptorsCollectionProvider.GetCollection()
at Microsoft.AspNet.Mvc.Core.DefaultActionDescriptorsCollectionProvider.get_ActionDescriptors()
at Microsoft.AspNet.Mvc.Routing.AttributeRoute.GetInnerRoute()
at Microsoft.AspNet.Mvc.Routing.AttributeRoute..ctor(IRouter target, IActionDescriptorsCollectionProvider actionDescriptorsCollectionProvider, IInlineConstraintResolver constraintResolver, ILoggerFactory loggerFactory)
at Microsoft.AspNet.Mvc.Routing.AttributeRouting.CreateAttributeMegaRoute(IRouter target, IServiceProvider services)
at Microsoft.AspNet.Builder.BuilderExtensions.UseMvc(IApplicationBuilder app, Action<IRouteBuilder> configureRoutes)
at Appname.Web.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory) in ... Startup.cs:line 75
Bạn không thể có con đường khác nhau có cùng tên .. .imagine khi tạo liên kết theo tên tuyến đường, nếu có nhiều tuyến đường có cùng tên, cái nào nên được chọn? ... hãy thử có các tên khác nhau như 'GetPaymentById',' GetPlanById', v.v. –
Như @KiranChalla nói s, MapRoutes của bạn có cùng tên mẫu. Nếu bạn cung cấp toàn bộ câu lệnh 'app.UseMvc' (bắt đầu dòng 75 đến cuối khai báo tuyến), ai đó chắc chắn sẽ cho bạn thấy chính xác phần nào cần thay đổi. –
@Daniel: Tôi đang đối mặt với một vấn đề tương tự. Giải pháp của bạn cho điều này là gì? –