asp.net - How to pass data from ajax javascript to MVC controller? -


in asp.net mvc project, have piece of javascript calls method in homecontroller.

$.ajax({             url: '@url.action("domultibook", "home")',             data: { "obj": mydataarray },             type: 'get',             datetype: "json",             cache:false,             success: function (data) {                },             error: function (data) {                 console.log("error " + data)              }          }); 

the mydataarray i'm passing this:

[{"userid":11,"bench":366,"dates":[["2015-9-30","all day"]]},{"userid":18,"bench":366,"dates":[["2015-9-30","all day"]]},{"userid":25,"bench":366,"dates":[["2015-9-30","all day"]]}] 

edit on controller have this,

    public void domultibook(multibookobject[] obj)     {         console.writeline(obj);      } 

and multibookobject class

public class multibookobject {     public int userid { get; set; }     public int bench { get; set; }     public string[] dates { get; set; } } 

how call controller method , pass data it?

edit question after suggestion

pass data

data: { "var": mydataarray }

        url: '@url.action("domultibook", "home")',          data: { "var": mydataarray },          type: 'get',         datetype: "json",         cache:false,         success: function (data) {            },         error: function (data) {             console.log("error getbookedbyuser " + data)          } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -