Asp.net core mvc send array of int to controller

Viewed 763

So I do Ajax and then I have this piece of code (JavaScript):

document.getElementById("HidenLink").style.visibility = "visible";
document.getElementById("HidenLink").innerHTML = "I have found " + data.pocetfound + " cases";
var arrStr = encodeURIComponent(JSON.stringify(data.listfound));
var Path = " ";
switch ('@ViewBag.TableName') {
         case "MYCASE":
              Path = "PATJ/PATHH"
         break;
       }
document.getElementById("HidenLink").href = Path + '/IDArr?array=' + arrStr;

Then I expect to get int[] IDArr in my Controller:

[HttpGet]
public async Task<IActionResult> MYRIGHTPATH(int? id, int[] IDArr)
{
  try {
    /*TESTS*/
     foreach (int i in IDArr) //Does not get executed
      {
         Console.WriteLine(i);
      }
        /*TESTS*/
   }catch (Exception e) {
                return RedirectToAction("Error", new { error = e });
            }
        }

My endpoint:

app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });

My problem is that controller does not get array I am trying to send.

Thanks for help!

1 Answers
Related