【问题标题】:Posting Integer List Back to MVC Action将整数列表发布回 MVC 操作
【发布时间】:2013-09-27 11:08:40
【问题描述】:

我在将整数列表的 jquery 帖子发回控制器中的操作方法时遇到问题。

我的帖子 jquery 如下:

    $.post('/Section/RunAlgorithm', {
        test: JSON.stringify([1, 2])
    }, function (response) {
    }, 'json');

我的控制器动作定义如下:

public ActionResult RunAlgorithm(int[] test)

发布到方法时,我的测试参数为空。我该如何解决这个问题?我的代码中哪里存在问题?

谢谢

【问题讨论】:

  • 我也尝试过不使用 JSON.stringify 并在操作中使用 IEnumerable。
  • { test: [1, 2] } 应该可以工作吗?
  • 谢谢,在以下帖子中找到了解决方案:stackoverflow.com/questions/7931832/…

标签: jquery asp.net-mvc


【解决方案1】:

我好累o___O ..这是解决方案:

    $.ajax('/Section/RunAlgorithm', {
        type: 'POST',
        traditional: true,
        data: {
            test: [1, 2, 3]
        }
    });

【讨论】:

  • 有趣。出于好奇,您使用的是哪个版本的 ASP.NET-MVC?
  • 我使用的是 4.5 版
猜你喜欢
  • 1970-01-01
  • 2011-03-13
  • 2014-11-19
  • 2013-03-16
  • 2011-10-13
  • 1970-01-01
  • 2013-06-21
  • 1970-01-01
  • 2012-06-03
相关资源
最近更新 更多