c# - json Array posting to mvc controller -


i want post json array mvc controller through ajax post as:

 $.ajax({                     type: 'post',                     data: json.stringify(totaldata),                     traditional:true,                     url: '/builder/save',                     success: function () {                         alert("playlist saved successfully!!");                     }                 }) 

and controller code have made array of 1 viewmodel & want update values as.

[httppost]     public actionresult save(ilist<itemeditviewmodel> data,long playlistid=0, string title="")     {             (int = 0; < data.count; i++)         {             var pc = db.playlistcontents.firstordefault(x => x.playlistcontentid == data[i].id);             if (pc == null)             {                 pc = new playlistcontent();                 db.playlistcontents.add(pc);             }             pc.contentmetadataid = data[i].metaid;             pc.playlistcontentsequenceid = + 1;         }   db.savechanges();             return redirecttoaction("playlist", new {id=playlistid });  } 

but object set null in controller.

my viewmodel as,

public class itemviewmodel {     public long id{get;set;}     public long metaid{get;set;} } 

try adding content type in ajax call,

contenttype : 'application/json', 

by default ajax sends content type application/x-www-form-urlencoded; charset=utf-8

edit

also dont know typo, json.stringify should json.stringify

hope helps.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -