传球达阵使用jquery邮政控制器 [英] Passing array to controller using jquery Post

查看:108
本文介绍了传球达阵使用jquery邮政控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var sc = new Array();
var i =0;
el.find(".colorable").each(function () {
    sc[i++] = $(this).attr("src");
});
$.post("/Edit/ChangeImageColor", { src : sc , s: source, t: target }, function () {
    alert("done");
});

我试图传递数组(SC)服务器,但它显示的src空

I am trying to pass array ( sc ) to server but it shows null in src

    public JsonResult ChangeImageColor(string[] src, string s, string t)
    {

谁能告诉我,我缺少的是什么?

Can anybody tell me what i am missing?

推荐答案

如果您使用的是ASP.NET MVC 3,你可以把它作为JSON请求:

If you are using ASP.NET MVC 3 you could send it as JSON request:

var sc = new Array();
var i = 0;
el.find(".colorable").each(function () {
    sc[i++] = $(this).attr("src");
});
$.ajax({
    url: '/Edit/ChangeImageColor',
    type: 'POST',
    contentType: 'application/json',
    data: JSON.stringify({ src: sc, s: source, t: target }),
    success: function() {
        alert("done");
    }
});

如果您使用的是ASP.NET MVC的旧版本可能会看一看的<一个href=\"http://haacked.com/archive/2010/04/15/sending-json-to-an-asp-net-mvc-action-method-argument.aspx\"相对=nofollow>以下博客帖子这说明了如何可以集成一个自定义的JSON提供工厂让您发送JSON请求控制器动作。

If you are using an older version of ASP.NET MVC you may take a look at the following blog post which illustrates how you could integrate a custom json provider factory allowing you to send JSON requests to controller actions.

这篇关于传球达阵使用jquery邮政控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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