0

I have the following javascript code:

   function myFunctionInJs (){
        var tbody = '';
        $.each(dataArray, function (index, item) {
            tbody += '<tr>
            <td>
            <a href="@Url.Action("MyAction", "MyController", new {Id = item.Id})">View</a>
            </td>
            </tr>';
        });
        $('#myTable').html(tbody);
    }

I want to assign Id = item.Id But I do not know how.

Tran Audi
  • 587
  • 1
  • 6
  • 22
  • What you're trying to do is not possible - at least not in the manner you're attempting. JS runs on the client *long* after the C# has completed execution on the server. If you want to send a JS value to C#, the most effective way would be to make an AJAX request – Rory McCrossan Jul 18 '17 at 10:39
  • @CarstenLøvboAndersen that won't work – Tran Audi Jul 18 '17 at 10:46
  • You can try, `function myFunctionInJs() { var url = '@Url.Action("MyAction", "MyController", new {Id = -1})' var tbody = ''; $.each(dataArray, function (index, item) { tbody += 'View'; }); $('#myTable').html(tbody); }` – Satpal Jul 18 '17 at 10:47

0 Answers0