locked
Sending List of Model as a parameter to Controller using Ajax RRS feed

  • Question

  • User1313979623 posted


    $JQ.ajax({
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    type: 'POST',
    url: '@Url.Action("GetFinalOrderIssue", "Application")',
    data: JSON.stringify({ ckhvalue: ckhvalue }),
    success: function (list) {
    debugger;

    if (list.length > 0) {
    $JQ.ajax({

    dataType: "json",
    type: "post",
    url: '@Url.Action("FinalOrderIssue", "Application")',
    data: JSON.stringify(list),

    success: function (result) {
    debugger;
    alert('generated successfully');


    },
    failure: function (response) {
    StopSpinner();
    }
    });
    }

    },
    failure: function (response) {
    StopSpinner();
    }
    });

    public ActionResult FinalOrderIssue(List<pgbsModel>[] list)
    {


    return Json(null);
    }

    Monday, July 22, 2019 12:12 PM

All replies

  • User475983607 posted

    Do you have a question?

    Monday, July 22, 2019 1:00 PM
  • User1520731567 posted

    Hi Mahalakshmi H N,

    According to your code,if your response has been list model,I suggest modify ajax and action,like:

    $JQ.ajax({
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    type: 'POST',
    url: '@Url.Action("GetFinalOrderIssue", "Application")',
    data: JSON.stringify({ ckhvalue: ckhvalue }),
    success: function (list) {
    debugger;
    
    if (list.length > 0) {
    $JQ.ajax({
    
    dataType: "json",
    type: "post",
    url: '@Url.Action("FinalOrderIssue", "Application")',
    data: JSON.stringify(list),
    data: { list: list }, success: function (result) { debugger; alert('generated successfully'); }, failure: function (response) { StopSpinner(); } }); } }, failure: function (response) { StopSpinner(); } });

    and remove [ ] in action:

    public ActionResult FinalOrderIssue(List<pgbsModel> list)
    {
    
    
    return Json(null);
    }

    Like the picture:

    Best Regards.

    Yuki Tao

    Tuesday, July 23, 2019 6:49 AM