0

I have the action ReportSsrs of a AffairesController

public async Task<IActionResult> ReportSsrs(
    int affaireId, 
    int[] coucheIds = null, 
    int[] secteurIds = null)
{
    return ...
}

I want to send an affair id and two arrays of ids couche and secteur

I try to use the following URL

//localhost:5001/affaires/reportssrs?affaireId=9&coucheIds[]=10&secteurIds[]=23

however what I get when I put a breakpoint and the action is hit, it does not seem to pass very well, the array value:
enter image description here

What is the correct way to pass an array via the URL to the action?

2
  • serialize those arrays before adding to the url Commented Apr 22, 2022 at 10:27
  • @J.Salas could you explain via an example? Commented Apr 22, 2022 at 10:31

1 Answer 1

2

The correct url should be:

localhost:5001/affaires/reportssrs?affaireId=9&coucheIds=10&secteurIds=10

If your array contains more than one item, the url should be:

[...]/reportssrs?affaireId=9&coucheIds=10&coucheIds=11&secteurIds=10&secteurIds=12
Sign up to request clarification or add additional context in comments.

2 Comments

what if multiple values?
Hi @serge, it works fine and model binding binds the property by name. Did you add any custom middleware or model binding in your project? How do you configure the route template? You can add [FromQuery] to all the parameters to check if it works or not.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.