How to pass array created from jQuery to controller method?

拈花ヽ惹草 提交于 2019-12-11 14:36:58

问题


My question may be a duplicate of this question. But, I don't get the returned values from the view into my controller.

As defined in the link, I have a model defined for the values that are returned.

But the difference is that, I am not using the AJAX call for this. I get the values of a row, turned into an Array of values by using this stmt:

    var arrayOf = $(currentSelected).get(0);
    var partialView = ('@Url.Action("PartialView")' + '/' + arrayOf);

here partialView correctly points to my controller method and control passes there.

but, my array there (in the controller) is always showing null in spite of correct values in 'arrayOf' and that I am not able to further proceed.

Here is my controller:

     public ActionResult PartialView(ChildColumns[] arrayOf) /*arrayOf is always null, WHY*/
    {
        //stmts
        return PartialView("ChildPartialView");
    }

Here ChildColumns is the model that has all the related fields.


回答1:


I would use an ajax call for this as mentioned by CM Kanode. something like

$.ajax({
    url: "@(Url.Action("PartialView", "Controller")",
    type: "POST",
    data: arrayOf
    cache: false,
    async: true,
    success: function (result) {
        $(".divContent").html(result);
    }
});


来源:https://stackoverflow.com/questions/20613184/how-to-pass-array-created-from-jquery-to-controller-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!