Accept multiple parameters for API in .NET Core 2.0 using attribute routing

Roddy Balkan

I have an incoming GET request as follows:

https://localhost:44329/api/scoInfo?activityId=1&studentId=1&timestamp=1527357844844

How would I create an endpoint in ASP.net-core that would accept this request.

I have tried different versions of the following and nothing works:

[HttpGet("{activityId: int}/{studentid: int}/{timestamp: int}")]
[Route("api/ScoInfo/{activityId}/{studentid}/{timestamp}")]
Nkosi

Use [FromQuery] to specify the exact binding source you want to apply.

//GET api/scoInfo?activityId=1&studentId=1&timestamp=1527357844844
[HttpGet("api/scoinfo")] 
public async Task<IActionResult> GetLearningTask(
    [FromQuery]int activityId, 
    [FromQuery]int studentId, 
    [FromQuery]int timeStamp) {
    //...
}

MVC will try to bind request data to the action parameters by name. MVC will look for values for each parameter using the parameter name and the names of its public settable properties.

Reference Model Binding in ASP.NET Core

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Accept multiple parameters for API in .NET Core 2.0

From Dev

.NET Core 2 API attribute routing configuration

From Dev

Attribute Routing with Parameters in Asp.Net Web API 2

From Dev

Multiple optional parameters web api attribute routing

From Dev

web api 2 versioning using attribute routing

From Dev

HTTP Attribute Same as Routing - ASP.Net Core API?

From Dev

Query string and attribute routing together for controller .NET core web API

From Dev

ASP.NET Core - API multiple parameters

From Dev

ASP.NET Web Api 2 - Subdomain Attribute Routing

From Dev

Pass multiple parameters in a POST API without using a DTO class in .Net Core MVC

From

Optional Parameters in Web Api Attribute Routing

From Dev

Web Api Optional Parameters in the middle with attribute routing

From Dev

Api Routing in .net core 3.0

From Dev

Attribute Routing in ASP.NET Core 1.0

From Dev

.NET Core 3.0 routing - conventional or attribute

From Dev

Replace custom placeholder in attribute routing in .NET CORE

From Dev

Attribute Routing in ASP.NET Core not working

From Dev

ASP.NET Core routing empty parameters

From Dev

How to pass multiple parameters from angular 8 to .NET Core API

From Dev

How to call API with multiple parameters from .NET Core MVC

From Dev

Asp.net core Routing with multiple optional parameters calling different action

From Dev

Web Api Attribute Routing with optional parameters and query parameters

From Dev

Routing with multiple parameters in ASP.NET MVC

From Dev

Web API 2 Attribute Routing for API Versioning

From Dev

JWT Authentication using a custom attribute in .NET Core Web API

From Dev

ASP.NET Core 2, OData v4 Attribute Routing

From Dev

How can i configure attribute based routing on startup file instead of using attribute on controller action in asp.net core mvc

From Dev

.net core razor pages multiple routing attributes

From Dev

Web API 2 routing - Route attribute

Related Related

  1. 1

    Accept multiple parameters for API in .NET Core 2.0

  2. 2

    .NET Core 2 API attribute routing configuration

  3. 3

    Attribute Routing with Parameters in Asp.Net Web API 2

  4. 4

    Multiple optional parameters web api attribute routing

  5. 5

    web api 2 versioning using attribute routing

  6. 6

    HTTP Attribute Same as Routing - ASP.Net Core API?

  7. 7

    Query string and attribute routing together for controller .NET core web API

  8. 8

    ASP.NET Core - API multiple parameters

  9. 9

    ASP.NET Web Api 2 - Subdomain Attribute Routing

  10. 10

    Pass multiple parameters in a POST API without using a DTO class in .Net Core MVC

  11. 11

    Optional Parameters in Web Api Attribute Routing

  12. 12

    Web Api Optional Parameters in the middle with attribute routing

  13. 13

    Api Routing in .net core 3.0

  14. 14

    Attribute Routing in ASP.NET Core 1.0

  15. 15

    .NET Core 3.0 routing - conventional or attribute

  16. 16

    Replace custom placeholder in attribute routing in .NET CORE

  17. 17

    Attribute Routing in ASP.NET Core not working

  18. 18

    ASP.NET Core routing empty parameters

  19. 19

    How to pass multiple parameters from angular 8 to .NET Core API

  20. 20

    How to call API with multiple parameters from .NET Core MVC

  21. 21

    Asp.net core Routing with multiple optional parameters calling different action

  22. 22

    Web Api Attribute Routing with optional parameters and query parameters

  23. 23

    Routing with multiple parameters in ASP.NET MVC

  24. 24

    Web API 2 Attribute Routing for API Versioning

  25. 25

    JWT Authentication using a custom attribute in .NET Core Web API

  26. 26

    ASP.NET Core 2, OData v4 Attribute Routing

  27. 27

    How can i configure attribute based routing on startup file instead of using attribute on controller action in asp.net core mvc

  28. 28

    .net core razor pages multiple routing attributes

  29. 29

    Web API 2 routing - Route attribute

HotTag

Archive