How can I send a JavaScript object to an ASP.NET Handler and extract its values?
I have defined a complex type object as follows:
function AccountObjCreate() {
var AccountsView = {};
AccountsView.Username = null;
AccountsView.Email = null;
AccountsView.Password = null;
return AccountsView;
}
I populate this object like so:
var aView = AccountObjCreate();
aView.Username = $('#tbUserName').val().trim();
aView.Email = $('#tbEmail').val().trim().toLowerCase();
aView.Password = $('#tbPassword').val().trim();
Then I make the following call:
$.post("/Handlers/AccountHandler.ashx", { obj: aView },
function (results) {
if (results.isSuccess) {
alert(results.msg);
} else {
alert(results.msg);
}
}, "json");
Upon inspecting the console, I can see all my data within aView displayed as JSON.
The code in my ASP.NET Handler page is:
context.Response.ContentType = "application/json";
context.Response.ContentEncoding = Encoding.UTF8;
string obj = context.Request["obj"];
However, the obj variable turns out to be NULL.