如何通过从jQuery的创建到控制器法阵? [英] How to pass array created from jQuery to controller method?

查看:139
本文介绍了如何通过从jQuery的创建到控制器法阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题可能是重复的<一个href=\"http://stackoverflow.com/questions/18112599/passing-array-from-javascript-to-controller-mvc-4\">this问题。但是,我没有得到从视图返回的值到我的控制器。

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.

但不同的是,我没有使用AJAX调用这一点。我得到一个连续的值,化作值的数组使用此语句:

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

在这里partialView正确地指向我的控制器方法和控制通过那里。

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

不过,我的阵中还有(控制器)始终显示为空,尽管在arrayOf'正确的价值观和我不能够进一步进行。

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.

下面是我的控制器:

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

下面ChildColumns是具有所有相关领域的典范。

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

推荐答案

由CM Kanode提到我会用Ajax调用这一点。像

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

这篇关于如何通过从jQuery的创建到控制器法阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆