How do I pass this js array to my MVC 3 controller?

前端 未结 7 2154
粉色の甜心
粉色の甜心 2020-12-31 16:58

I am getting null values in the controller. Not sure what am I am missing.

I have a grid where I have a list of guests (with name & email) where user select gues

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-31 17:36

    Maybe changing setting traditional to true might help. Here is (modified) code that I used to post unique identifiers (Guids) to the controller action.

    var yourArray = new Array();
    // TODO: fill array with ids of checked checkboxes
    $('.CBC:checked').each(function () {
       yourArray.push($(this).attr('myId'));
    });
    
    var postData = {
        yourArray: yourArray
    };
    
    $.ajax({
        type: "POST",
        url: "/ctrl/ActionName",
        data: postData,
        success: function (result) {
        },
        datatype: "json",
        traditional: true
    });
    

    In the controller I have following action.

    [HttpPost]
    public ActionResult ActionName(List yourArray)
    {
        return View();
    }
    

提交回复
热议问题