Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
Post list using jquery ajax

I have this code in razor

@{
    var aid = new List<int>();
    foreach (var item in Model.applications)
    {
        if (item.Status == 1)
        {
            aid.Add(item.Id);
        }
    }
}

and in js I have this:

<script>
function checkIfSigned() {

    var data = { aid: @aid };
    console.log(data);

    $.ajax({
        url: '@Url.Action("Method", "Controller")',
        type: "POST",
        data: data,
        ...
    });
}

and in my controller:

public JsonResult Method(List<int> aid)
{
  foreach (var item in aid)
  { ... }
}

my problem is:

var data = { aid: @aid };

It throws an exception:

Uncaught SyntaxError: Unterminated template literal

var data = { aid: System.Collections.Generic.List`1[System.Int32] };

What can I do? how can I post list?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can do like that :

var data = []; // javascript array
@foreach(var item in Model.applications)
{
    if (item.Status == 1)
    {
        <text> 
           /* start JS */
           data.push('@item.Id'); 
           /* end JS */
        </text>
    }
}

and in JS Ajax :

    <script>
    function checkIfSigned() {

        console.log(data);

        $.ajax({
            url: '@Url.Action("Method", "Controller")',
            type: "POST",
            data: data,
            ...
        });
    }
    </script>
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!