In asp.net MVC project, I have this piece of javascript that calls a 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 is something like 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 then on my controller I have this,
public void doMultiBook(multiBookObject[] obj)
{
Console.WriteLine(obj);
}
and this is my multiBookObject class
public class multiBookObject
{
public int userID { get; set; }
public int bench { get; set; }
public string[] dates { get; set; }
}
How do i call a controller method and pass some data to it?
edit my question after suggestion
string varmake it an object that matches your JSON Definition, so basically an array of objects that hasuserId,bench, and an array of `date's. You're not passing a string, you're passing a JSON object so your C# needs an object that matches it.datesisn't an array of strings. You have an array of string arrays based on your JSON.