Search code examples
jqueryajaxcontrollerjqgrid

Fetch Data From jquery (Ajax) to Controller in IEnumerable<--------->


Hello Am Facing problem in Fetching Data and Transferring to Controller

Below is My JQuery Code Using Ajax

$("#save").click(function () {
       
        $.ajax({
            type: 'POST',
            url: '/PCM/PCMPost',
            dataType: "json",
            data: { final: JSON.stringify(final) },
            //data: JSON.stringify({ final: final }),
            success: function (data) {
                alert("Succeded");
            }
        })
    })

intialized like this

var final=[];

final array looks like after push operation, in console and it has expected data to

(2)[{...},{...}] 

controller code

public ActionResult PCMPost(IEnumerable<ProductCategaryMapping> final)
{
      return RedirectToAction("ProductCategaryMappingDisplay", "PCM");
}

while debugging "final" is showing null

i dont know where am going wrong please help me out


Solution

  • Send data without converting it to string.

    $("#save").click(function () {
       
        $.ajax({
            type: 'POST',
            url: '/PCM/PCMPost',
            dataType: "json",
            data: { final:final },           
            success: function (data) {
                alert("Succeded");
            }
        })
    })