【发布时间】:2018-05-09 03:37:05
【问题描述】:
我希望能够使用同一 URL 上发布的 JSON 或表单数据。
就目前而言,我得到:
fail: Microsoft.AspNetCore.Mvc.Internal.ActionSelector[1]
Request matched multiple actions resulting in ambiguity. Matching actions:
:
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HLDLB0LJCPJ4", Request id "0HLDLB0LJCPJ4:00000001": An unhandled exception was thrown by the application.
Microsoft.AspNetCore.Mvc.Internal.AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:
https://andrewlock.net/model-binding-json-posts-in-asp-net-core/ 建议使用不同的端点,但在这种情况下我不能这样做。
https://massivescale.com/web-api-routing-by-content-type/ 建议为 asp.net 提供一种方法,例如:
[ContentTypeRoute("api/test/bytype", "application/json")]
或
[ContentTypeRoute("api/test/bytype", "application/x-www-form-urlencoded")]
但在 .net 核心中,我们没有 System.Web.Http.Routing。也许可以移植到使用 Microsoft.AspNetCore.Mvc.Routing... 但是有什么东西可以代替 IHttpRouteConstraint
我的问题:.net core mvc 中是否已经内置了类似的东西?
例如在Java的JAX-RS中,有@Consumes("application/json")
【问题讨论】:
标签: asp.net-core-mvc asp.net-core-2.0