I want to pass list through AJAX. How can I do this and assign value on runtime. I am doing it, but it pass null value. Here is my code.
JQuery:
Assuming TradelaneDetailViewModel
contains properties id
and color
, then the script needs to be
var items = [];
for (var i = 0; i < 5; i++) {
items.push({ id: i, color: 'Level' + i });
}
$.ajax({
url: '@Url.Action("test123", "ConfigurableTradeLane")',
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ viewmodel: items }),
success: function (data) {
//alert("success");
},
error: function (jqXHR, exception) {
alert('Error message.');
}
});