I have a function in AJAX that is the click
event of a button where I get all the checkbox
that are checked and get the values of each one and play in an array like this:
$("#btnDropMessageSents").click(function (e) {
var ids = [];
$("#inbox-table input[type=checkbox]:checked").each(function () {
if (this.checked === true) {
ids.push($(this).val());
}
});
if (ids.length > 0)
{
$.ajax({
url: '/Inbox/DeleteDefinitive',
type: "POST",
contentType: "application/json; charset=utf-8",
data: values = [{ 'values': '1006' }, { 'values': '1005' }, { 'values': '1004' }],
dataType: "json",
traditional: true,
success: function (data, status, xhr) {
alert(data);
},
error: function (data) {
console.log(data);
}
});
}
})
In the line data: values
I put values in the same hand to see if it would work anyway it was not.
My ActionResult
in the controller looks like this:
[HttpPost]
public ActionResult DeleteDefinitive(string[] values)
{
var MensagemEnviadaDomain = new MensagemEnviada();
foreach (var item in values)
{
var Model = MensagemEnviadaDomain.GetItem(_ => _.COD_MENSAGEM == Convert.ToInt32(item));
MensagemEnviadaDomain.Edit(new MensagemEnviadaDto()
{
COD_MENSAGEM = Model.COD_MENSAGEM,
COD_AUTOR = Model.COD_AUTOR,
COD_REMETENTE = Model.COD_REMETENTE,
ID = Model.ID,
STATUS_AUTOR = Model.STATUS_AUTOR,
STATUS_REMETENTE = "E",
});
}
return (RedirectToAction("Sent", "Inbox"));
}
I have tried a lot of times and different ways in my AJAX function I do not know what it might be but the error it gives is always the same:
Error 500 Internal Server Error
But this error occurs because my array of values
arrives empty ie as null
in action ... How to fix this?