IT業界のすみっこ暮らし

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



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

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...
}




プライバシーポリシー