IT業界のすみっこ暮らし

ふと気がついたときの記録

Passing A List Of Objects Into An MVC Controller Method Using jQuery Ajax


AjaxでリストオブジェクトをControllerに渡す

stackoverflow.com

JS

var things = [
    { id: 1, color: 'yellow' },
    { id: 2, color: 'blue' },
    { id: 3, color: 'red' }
];
$.post('@Url.Action("PassThings")', { things: things },
   function () {
        $('#result').html('"PassThings()" successfully called.');
   });

Controller

[HttpPost]
public void PassThings(IEnumerable<Thing> things)
{
    // do stuff with things here...
}


プライバシーポリシー