javascript - getting null value in list when passing by ajax call to mvc controller -


i passing list mvc controller getting null value in controller.but list has values when show in alert on client side.

ajax call

$("#addtiles").click(function() {     usertiles = json.stringify({         'usertiles': usertiles     });     alert("entered function.");     alert(usertiles[0].tileid);     var url = '@url.action("addtiles")';     $.ajax({         type: "get",         url: url,         data: usertiles,         success: function(d) {             if (d.indexof('"issessionexpired":true') != -1) {                 location.reload();             } else {                 onaddtilessuccessful(d);             }         },         error: function() {             errorinoperation();         },         contenttype: "application/html; charset=utf-8",         datatype: 'html'     }); });  function onaddtilessuccessful(e) {     $("#tilessubmissionmsg").append(e); }  function errorinoperation(d) {     $("#tilessubmissionmsg").append("something went wrong"); } 

mvc controller

  public actionresult addtiles(list<usertilesvm> usertiles)     {         return view();     } 

list model

public class usertilesvm {     public int tileid { get; set; }     public int topposition { get; set; }     public int leftposition { get; set; } } 

list in javascript

"{"usertiles":[{"tileid":"3","topposition":0,"leftposition":0}]}" 

i have tried sending list stringfy doesn't work.

use : [httpget] on method addtiles have used type: "get" on ajax hit.

[httpget] public actionresult addtiles(list<usertilesvm> usertiles) {      return view(); } 

if still doesn't works try type: "post" on ajax hit , on method use [httppost]

[httppost] public actionresult addtiles(list<usertilesvm> usertiles) {     return view(); } 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -