all,
I'm getting to my webmethod in my code behind but I'm having problems deserializing my json data. I have no good reference but here is what I"m trying to do. My the code in my webmethod is not allowing me to get the data out passed from my ajax call. thanks for any help.
$("[id$=rdbSaveAjax1]").click(function () {
var mappedJobRole = new Array();
$(".jobRole").each(function (index) {
var jobRoleIndex = index;
var jobRoleID = $(this).attr('id');
var jobRoleName = $(this).text();
// add all the roleids and rolenames to the job role array.
var roleInfo = {
"roleIndex": jobRoleIndex,
"roleID": jobRoleID,
"roleName": jobRoleName
};
queryStr = { "roleInfo": roleInfo };
mappedJobRole.push(queryStr);
});
$.ajax({
type: "POST",
url: "Apage.aspx/Save_Mapped_Role",
data: "{'savedRole': " + JSON.stringify(mappedJobRole) + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (data) {
alert("successfully posted data");
},
error: function (data) {
alert("failed posted data");
}
});
});
In my code behind I can't seem to get the data out. My class:
public class MappedRole
{
public int Index { get; set; }
public string RoleID { get; set; }
public string RoleName { get; set; }
}
My webmethod:
[WebMethod]
public static bool Save_Mapped_Role(object savedRole)
{
bool success = false;
JavaScriptSerializer js = new JavaScriptSerializer();
IList<MappedRole> role = new JavaScriptSerializer().Deserialize<IList<MappedRole>>savedRole);
int Index = role[0].Index;
string RoleID = role[0].RoleID;
string RoleName = role[0].RoleName;
return success;
}