The console is showing me an error stating that the parameters dictionary contains a null entry for parameter wantedids
. I am trying to pass checked boxes to my controller using an array, so only the admin can check all boxes of tips for a specific user. The admin has more than 5 users. Although I am successfully passing the checked elements in my console, it displays an error message saying Internal server error
. Can someone help me understand how to update my database with the checked boxes?
<input type="checkbox" class="cktips" idtips="@item.idtips
checked="@(item.iduser == ViewBag.iduser ? true : false)"/>
.js var wantedids = [];
$("#btnClick").click(function () {
$(".cktips").each(function () {
$(this).prop('checked', true);
ids.push($(this).val());
});
$.ajax({
url: UrlSettingsDocument.Tips,
data: { ids: ids},
type: "POST",
success: function () {
alert('successs');
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
})
})
This is my Controller.cs file
public JsonResult Statics(bool ids,int iduser,int idtips)
{
try
{
if (ids)
{
statics = new statics ();
st.idtips= idtips;
Database.statics .Add(st);
Database.SaveChanges();
}
else if (!ids)
{
var stdelete= Database.statics.Where(a => a.iduser == iduser &&
a.idtips== idtips).FirstOrDefault();
Database.statics.Remove(stdelete);
Database.SaveChanges();
}
if (Request.IsAjaxRequest())
{
return Json(true, JsonRequestBehavior.AllowGet);
}
else
{
return Json(true, JsonRequestBehavior.AllowGet);
}
}
catch (Exception ex)
{
Logger.Error("Error: {0}", ex.ToString());
return null;
}