Click here to Skip to main content
15,888,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Failed to load resource: the server responded with a status of 500 (Internal Server Error) When using JqGrid AND CHECK duplicate record when insert.
HTML
$(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";
}

C#
[HttpPost]
          public ActionResult Addtemp(typebaker postData)
          {
              Classtypebaker _Classbaker = new Classtypebaker();
              //todo: Add temp to repository
              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);
                //  return Json(true);
              }
            ///  return Json(true);
          }
Posted
Comments
Richard MacCutchan 4-Jan-15 7:14am    
You need to show where the error occurred.
[no name] 4-Jan-15 7:19am    
No need to post the entire peice of code. 500 Internal Server error is from the Controller Action method. So put a debugger and test where the error is thrown. You can better achieve that by adding the implementation in a try catch block.
Member 4424465 4-Jan-15 9:53am    
- Also Doing the below may Help:
- Check the Application Pool of the Service is still running, case point password changed on identity, will shut it down and that would return 500.

- After you have debugged this as others have suggested. You can also put register an Exception Filter to handle unhandled exceptions and just check the server's log, include the stack trace and message
details:
http://www.asp.net/web-api/overview/error-handling/exception-handling

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900