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?
var data = { aid: @Html.Raw(Json.Encode(aid)) };and the you needdata: JSON.stringify(data);andcontentType: 'application/json',