Home > Blockchain >  Send an array to a Controller action via UrlParams
Send an array to a Controller action via UrlParams

Time:04-22

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?

CodePudding user response:

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
  • Related