首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用jQuery Ajax将对象列表传递给MVC控制器方法

使用jQuery Ajax将对象列表传递给MVC控制器方法
EN

Stack Overflow用户
提问于 2012-11-06 08:01:08
回答 10查看 328.3K关注 0票数 123

我尝试使用jQuery的ajax()函数将一个对象数组传递给一个MVC控制器方法。当我进入PassThing() C#控制器方法时,参数"things“为空。我尝试过使用List类型作为参数,但也不起作用。我做错了什么?

代码语言:javascript
复制
<script type="text/javascript">
    $(document).ready(function () {
        var things = [
            { id: 1, color: 'yellow' },
            { id: 2, color: 'blue' },
            { id: 3, color: 'red' }
        ];

        $.ajax({
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            type: 'POST',
            url: '/Xhr/ThingController/PassThing',
            data: JSON.stringify(things)
        });
    });
</script>

public class ThingController : Controller
{
    public void PassThing(Thing[] things)
    {
        // do stuff with things here...
    }

    public class Thing
    {
        public int id { get; set; }
        public string color { get; set; }
    }
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13242414

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档