can i retrieve an json object in a asp.net mvc controller?
Here's my ajax request
// get form values
var nameValue = $("#name").val();
var ageValue = $("#age").val();
// json object
var person = {
name: nameValue,
age: ageValue
};
$.ajax({
url: '/Home/GetData',
type: 'POST',
data:{userObj: person},
success: function (data, textStatus) {
alert(data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Erro :" + XMLHttpRequest.responseText + "| " + textStatus + "| " + errorThrown);
}
});
And here's my asp.net MVC controller method
[HttpPost]
public String GetData(dynamic userObj)
{
dynamic person = System.Web.Helpers.Json.Decode(userObj);
return userObj.name; // It didn't work
}
I want to retrieve this object in my controller, and use it as userObj.name, userObj.age like a json object inside C# with no need to create a C# class with same parameters to this.
Is there some way?