FromUri in ASP.NET CORE 2.0

后端 未结 2 1316
谎友^
谎友^ 2020-12-25 10:09

This question is because in my MVC project with ASP.NET CORE 2.0, I can not add the [FromUri] attribute to my drivers.

I tried using li

相关标签:
2条回答
  • 2020-12-25 10:23

    I think you might be looking for [FromQuery]: https://docs.microsoft.com/en-us/aspnet/core/mvc/models/model-binding#customize-model-binding-behavior-with-attributes

    [FromUri] is used in Asp.Net WebApi 2, not asp.net core

    0 讨论(0)
  • 2020-12-25 10:37

    TLDR : You can use [FromQuery] and [FromRoute] in place of [FromUri]


    As Mike_G stated in his answer you can use [FromQuery] attribute in place of [FromUri]. But you might also need to use [FromRoute] in certain cases as pointed by Muhammad Umar in comments.

    FromRoute

    This attribute is used when the parameter is passed as the part of the URL string.

    Ex: api/countries/1

    FromQuery

    As the name implies, FromQuery parameters has to be passed as query strings.

    Ex: api/countries?id=1

    References:

    1. FromRoute - Microsoft Docs
    2. FromQuery - Microsoft Docs
    3. FromUri - Microsoft Docs
    0 讨论(0)
提交回复
热议问题