List pass through ajax in ASP.Net MVC

前端 未结 1 507
失恋的感觉
失恋的感觉 2021-01-17 07:44

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:

相关标签:
1条回答
  • 2021-01-17 08:22

    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.');
        }
    });
    
    0 讨论(0)
提交回复
热议问题