Failed to load resource: the server responded with a status of 500 (Internal Server Error) When using JqGrid AND CHECK duplicate record when insert.
$(document).ready(function () {
$.jgrid.formatter.integer.thousandsSeparator = ',';
$.jgrid.formatter.number.thousandsSeparator = ',';
$.jgrid.formatter.currency.thousandsSeparator = ',';
$('#list').jqGrid({
caption: "رسته نان",
//url from wich data should be requested
url: '@Url.Action("Gettemps", "TypeBread")',
//url for edit operation
editurl: '@Url.Action("Edittemp", "TypeBread")',
//type of data
datatype: 'json',
jsonReader: {
root: "Rows",
page: "Page",
total: "Total",
records: "Records",
repeatitems: true,
userdata: "UserData",
id: "ID_Baker",
cell: "RowCells"
},
//url access method type
mtype: 'POST',
//columns names
colNames: [' نام رسته ', 'شماره', ' '],
//columns model
colModel: [
{
name: '@(StronglyTyped.PropertyName<typebaker>(x => x.FNameTypeBaker))',
index: '@(StronglyTyped.PropertyName<typebaker>(x => x.FNameTypeBaker))',
align: 'right', width: 400,
editable: true, edittype: 'text', hidden: false,
editoptions: {
maxlength: 100
},
editrules: {
required: true
}
},
{
name: '@(StronglyTyped.PropertyName<typebaker>(x=>x.ID_Baker))',
index: '@(StronglyTyped.PropertyName<typebaker>(x => x.ID_Baker))',
align: 'right', width: 170,
editable: false, hidden: true, key: true
},
{
name: 'myac', width: 80, fixed: true, sortable: false,
resize: false, formatter: 'actions',
formatoptions: {
keys: true,
delbutton: true,
delOptions: {
url: '@Url.Action("Deletetemp", "TypeBread")',
}
}
}
],
//pager for grid
pager: $('#pager'),
//number of rows per page
rowNum: 10,
rowList: [10, 20, 50, 100],
//initial sorting column
sortname: 'ID_Baker',
//initial sorting direction
sortorder: 'asc',
//we want to display total records count
viewrecords: true,
width: '800',
shrinkToFit: false,
height: 'auto',
hidegrid: false,
direction: "rtl",
gridview: true,
rownumbers: true,
loadComplete: function () {
//change alternate rows color
$("tr.jqgrow:odd").css("background", "#E0E0E0");
},
loadError: function (xhr, st, err) {
jQuery("#rsperror").html("Type: " + st + "; Response: " + xhr.status + " " + xhr.statusText);
},
multiselect: true
}).jqGrid('gridResize', { minWidth: 400 });
});
var lastSel;
function inlineEdit() {
$('input[name=rdEditApproach]').attr('disabled', true);
$('#list').navGrid(
'#pager',
//enabling buttons
{ add: true, del: true, edit: false, search: false },
//edit options
{},
//add options
{ width: 'auto', url: '@Url.Action("Addtemp", "TypeBread")' },
//delete options
{ url: '@Url.Action("Deletetemp", "TypeBread")' }
);
//add onSelectRow event to support inline edit
$('#list').setGridParam({
onSelectRow: function (id) {
if (id && id != lastSel) {
//save changes in row
$('#list').saveRow(lastSel, false);
lastSel = id;
}
//trigger inline edit for row
$('#list').editRow(id, true);
}
});
};
function formEdit() {
$('input[name=rdEditApproach]').attr('disabled', true);
$('#list').navGrid(
'#pager',
//enabling buttons
{ add: true, del: true, edit: true, search: false },
//edit option
{
width: 'auto', checkOnUpdate: true, checkOnSubmit: true,
beforeShowForm: function (form) {
centerDialog(form, $('#list'));
}
},
//add options
{
width: 'auto', url: '@Url.Action("Addtemp", "TypeBread")',
reloadAfterSubmit: true, checkOnUpdate: true, checkOnSubmit: true,
beforeShowForm: function (form) {
centerDialog(form, $('#list'));
}
},
//delete options
{
url: '@Url.Action("Deletetemp", "TypeBread")', reloadAfterSubmit: true
})
//.jqGrid('navButtonAdd', "#pager", {
// caption: "حذف ردیفهای انتخابی", title: "Delete Toolbar", buttonicon: 'ui-icon ui-icon-trash',
// onClickButton: function () {
// var idsList = jQuery("#list").jqGrid('getGridParam', 'selarrrow');
// alert(idsList);
//jQuery("#list").jqGrid('delGridRow',idsList,{reloadAfterSubmit:false});
// }
//});
};
function centerDialog(form, grid) {
var dlgDiv = $("#editmod" + grid[0].id);
var parentDiv = dlgDiv.parent(); // div#gbox_list
var dlgWidth = dlgDiv.width();
var parentWidth = parentDiv.width();
var dlgHeight = dlgDiv.height();
var parentHeight = parentDiv.height();
var parentTop = parentDiv.offset().top;
var parentLeft = parentDiv.offset().left;
dlgDiv[0].style.top = Math.round(parentTop + (parentHeight - dlgHeight) / 2) + "px";
dlgDiv[0].style.left = Math.round(parentLeft + (parentWidth - dlgWidth) / 2) + "px";
}
[HttpPost]
public ActionResult Addtemp(typebaker postData)
{
Classtypebaker _Classbaker = new Classtypebaker();
if (postData == null)
return Json(false);
int baker = _Classbaker.checkbaker(postData.FNameTypeBaker);
if (baker <= 0)
{
db.typebakers.Add(postData);
db.SaveChanges();
return Json(true);
}
else
{
ViewBag.Name = "this dublicate record";
return View(ViewBag.Name);
}
}