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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -