Passing json list to MVC 3

后端 未结 3 1754
时光取名叫无心
时光取名叫无心 2021-01-05 22:02

I am trying to submit this with Ajax to a MVC3 controller:

    var params = {
        \'productId\': productId,
        \'list\': []
    };

    $.each($(\'.         


        
3条回答
  •  一个人的身影
    2021-01-05 22:53

    Try changing your controller action to (I'm assuming here that Specification is a model representing the JSON you're trying to post):

    public Boolean Save(Int32 productId, List specifications)
    

    And then change these things in your JS:

    var params = {
        'productId': productId,
        'specifications': []
    };
    
    params.specifications.add(specification);
    
    $.ajax({
        type: "POST",
        url: "/Admin/Product/Save/",
        data: JSON.stringify(params),
        contentType: 'application/json',
        success: function () { alert('done'); }
    });
    

提交回复
热议问题