Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Send an array to a Controller action via UrlParams

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

//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?

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading