Everything works as expected until the json string is deserialized after the post back.
Class:
public class RegretLetterDetail
{
public int PositionID { get; set; }
[Display(Name = "Description of Position")]
public string PositionReference { get; set; }
public string PositionName { get; set; }
public int PayrollNumber { get; set; }
[Display(Name = "Name of Candidate")]
public string PersonName { get; set; }
public bool PersonSelected { get; set; }
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
[Display(Name = "Send")]
public DateTime DateSend { get; set; }
public bool IsDeleted { get; set; }
public bool Undelete { get; set; }
[Display(Name = "Changed By")]
public string ChangedBy { get; set; }
public bool SendEmial { get; set; }
public bool SendSMS { get; set; }
}
jQuery Serialization:
$.fn.serializeObject = function () {
var o = {};
var a = this.serializeArray();
$.each(a, function () {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
Ajax Postback:
var DetailParam = "@Html.Raw(Url.Action("_RegretPersonSelect", "Home"))";
var DetailData = JSON.stringify($('#_PersondetailRegret').serializeObject());
$.ajax({
type: 'POST',
url: DetailParam,
data: DetailData,
success: function (result) {
$("#RegretLetterto").html(result);
}
});
JsonString:
"{\"__RequestVerificationToken\":\"ZQn4bLDapqavi7dagatgluRffgxJGSJYHlRdMOXyzHN_LLPKrDZjdDUTVwYiLaOd8oTnt1Tqzw0deLLADlZbtvGZdIhUIPPRBzmQx_grHnBCnk15qfHMN3rds9Xy7eQs0\",
\"[0].PersonSelected\":[\"true\",\"false\"],\"[0].PayrollNumber\":\"100001\",\"[0].SendSMS\":[\"true\",\"false\"],
\"[1].PersonSelected\":[\"true\",\"false\"],\"[1].PayrollNumber\":\"100002\",\"[1].SendSMS\":[\"true\",\"false\"],
\"[2].PersonSelected\":[\"true\",\"false\"],\"[2].PayrollNumber\":\"100003\",\"[2].SendSMS\":[\"true\",\"false\"],
\"[3].PersonSelected\":[\"true\",\"false\"],\"[3].PayrollNumber\":\"100005\",\"[3].SendSMS\":[\"true\",\"false\"],
\"[4].PersonSelected\":[\"true\",\"false\"],\"[4].PayrollNumber\":\"100006\",\"[4].SendSMS\":[\"true\",\"false\"]
}"
Deserialization Code:
System.Web.Script.Serialization.JavaScriptSerializer serializer =
new System.Web.Script.Serialization.JavaScriptSerializer();
model = (List<RegretLetterDetail>)serializer.Deserialize(
jsonString, typeof(List<RegretLetterDetail>));
The deserialize object returned is always empty. How / What do I need to do to make sure that the list of values is successfully desterilized. What potentially obvious thing am I missing?