如何将多个jQuery数组发送到MVC控制器? [英] How to send multiple jQuery arrays to an MVC controller?

查看:79
本文介绍了如何将多个jQuery数组发送到MVC控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用jquery创建并填充了各种数组.第一次尝试将JavaScript数组发送到MVC控制器.

I have created and filled various arrays using jquery. First time, trying to send JavaScript arrays to MVC controller.

我可以举个例子吗?如何发送数组和其他变量?在控制器端,如何获取数据?

Can I have an example how to do that? How can I send the arrays and other variables as well? On the controller side, how can I retrieve the data?

推荐答案

您可以使用逗号或管道分隔输入内容,另一方面,只需对其进行语法分析就可以使事情变得简单.或者,如果您想以正确的面向对象的方式进行操作,则可以使用以下代码:

You can comma or pipe delimit your input and on the other end just parse it to keep things simple. Or if you want to do things the right object oriented way you could use the following code:

var object1 = $(".ControlArrayClass").val(); 
var object2 = $(".ControlArrayClass2").val(); 
$.post('mycontroller/myactionmethod', function( variable1: object1, variable2: object2});

在控制器端看起来像这样

and on the controller end it would look like this

public ActionResult myactionmethod(Guid[] variable1, String[] variable2)
{
//do whatever here
return View(); 
}

希望这会有所帮助.

这篇关于如何将多个jQuery数组发送到MVC控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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