I'm catching the post in my controller, but the String formData is null. Because of this, I'm also unable to use the Anti Forgery Attribute, since it seems like all the data is lost. Maybe I shouldn't be using serialzeArray?
My Post:
$("#SetCommunicationSettingsForm").submit(function (e) {
debugger;
var postData = $(this).serializeArray();
var formURL = $(this).attr("action");
$.ajax(
{
url: formURL,
type: "POST",
datatype:"json",
data: postData,
success: function (data) {
debugger;
//data: return data from server
if (data.success == true) {
$("#SaveSuccessful").show();
$("#SetCommunicationSettingsFormArea").hide();
$("#SumbitCommunicationSettingForm").val('<%: ServiceSite.Resources.Resources.COMMON_CLOSE %>');
$("#SumbitCommunicationSettingForm").unbind('click');
$("#SumbitCommunicationSettingForm").click(closeCommunicationSettingPopup);
$("#CancelCommuncationSettingButton").hide();
}
else {
$("#DeviceCommuncationSettingLocation").html(data);
}
}
});
e.preventDefault(); //STOP default action
});
My controller:
[HttpPost]
//[AuthorizeActionFilter]
//[ValidateAntiForgeryToken (Salt= "UpdateCommunicationSettings")]
public ActionResult UpdateCommunicationSettings(String formData)
{
//Decode parameters
JavaScriptSerializer ser = new JavaScriptSerializer();
Dictionary<String, Object> jsonParams = ser.Deserialize<Dictionary<String, Object>>(formData);
//verify permissions on server side
if (((List<string>)Session["AuthorizedActions"]).Contains("EditDeviceCommunicationSettings"))
{
// Build DeviceData.DeviceConfigurationSettings from model, pass to DAL to Save
List<long> deviceIds = GetSelectedDevicesFromSession();
foreach (long id in deviceIds)
{
}
return PartialView("DeviceCommunicationSettingDialog");
}
else
{
return Json(new { notAuthorized = true });
}
}