How to pass array created from jQuery to controlle

2019-08-30 06:51发布

问题:

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);
    }
});