jquery - JQGrid Displaying Server Errors -


i have tried several solutions found here , elsewhere on web still can't server sent errors display on jqgrid edit form. have put breakpoints in aftersubmit method of jqgrid it's never hit. have simplified show alert if method executed nothing working. end stacktrace displayed header of edit form. did miss?

jqgrid code

<script type="text/javascript" language="javascript">     $(document).ready(function() {         $("#jqgrid1").jqgrid({             url: '@url.action("getdata", "invoicetype")',             editurl: '@url.action("editdata", "invoicetype")',             mtype: "get",             datatype: "json",             page: 1,             colmodel: [                 { editable: true, editoptions: { readonly: "readonly" }, key: true, width: 60, label: "id", name: "id", hidden: false },                 { editable: true, width: 250, label:"name", name: "name", hidden: false },                 { editable: true, editoptions: { readonly: "readonly" }, width: 175, label: "date created", name: "datecreated", align: 'right', hidden: false, formatter: "date", formatoptions: { srcformat: "m/d/y h:i:s a", newformat: "m/d/y h:i:s a" } },                 { editable: true, editoptions: { readonly: "readonly" }, width: 175, label: "date updated", name: "dateupdated", align: 'right', hidden: false, formatter: "date", formatoptions: { srcformat: "m/d/y h:i:s a", newformat: "m/d/y h:i:s a" } },                 { editable: true, editoptions: { readonly: "readonly" }, width: 200, label: "created by", name: "updatedby", hidden: false },                 //{ editable: true, editoptions: { readonly: "readonly" }, width: 50, label: "active", name: "active", hidden: false },                 { editable: true, editoptions: { value: "1:0" }, edittype: "checkbox", width: 50, label: "active", name: 'active', index: 'active', formatter: 'checkbox', align: 'center', stype: "select", searchoptions: { value: "1:yes;0:no" } },             ],             height: "350",             autowidth:true,             shrinktofit: false,             caption: "invoice types",             rownum: 10,             pager: "#jqgrid1_pager",             rowattr: function (rd) {                 if (rd.active === 'false') {                     return { "class": "myaltrowclass" };                 }             },             loadcomplete: function () {                 //alert("ok");             },             loaderror: function(jqxhr, textstatus, errorthrown) {                 alert('http status code: ' + jqxhr.status + "\n" +                     'textstatus: ' + textstatus + "\n" +                     'errorthrown: ' + errorthrown);                 alert('http message body (jqxhr.responsetext): ' + "\n" + jqxhr.responsetext);             },          }).jqgrid('navgrid', '#jqgrid1_pager', { edit: true, add: true, del: true, search: false, view: true, refresh: true },         {             // edit options             editcaption: "the edit dialog",             recreateform: true,             checkonupdate: true,             checkonsubmit: true,             closeafteredit: true,             height: 'auto',             width:'auto',             errortextformat: function (response) {                 return '<span class="ui-icon ui-icon-alert" ' +                              'style="float:left; margin-right:.3em;"></span>' +                             response.responsetext;             },             aftersubmit: function (response) {                 var myinfo = '<div class="ui-state-highlight ui-corner-all">' +                              '<span class="ui-icon ui-icon-info" ' +                                  'style="float: left; margin-right: .3em;"></span>' +                              response.responsetext +                              '</div>',                     $infotr = $("#tblgrid_" + $.jgrid.jqid(this.id) + ">tbody>tr.tinfo"),                     $infotd = $infotr.children("td.topinfo");                 $infotd.html(myinfo);                 $infotr.show();                  // display status message 3 sec                 settimeout(function () {                     $infotr.slideup("slow");                 }, 3000);                  return [true, "", ""]; // response should interpreted successful             }          },         {             //add options             closeafteradd: true,             recreateform: true,             height: 'auto',             width: 'auto',             errortextformat: function (data) {                 return 'error: ' + data.responsetext             }          },         {             // del options             errortextformat: function (data) {                 return 'error: ' + data.responsetext             }         },         {             //search          },         {             //view details form             height: 'auto',             width: '400',         });     });  </script> 

web api controller method code

[responsetype(typeof(httpresponsemessage))] [httpput] public httpresponsemessage put(int id, [frombody] invoicetypemodel item) {     if (item == null)         return request.createerrorresponse(httpstatuscode.badrequest, "could not read invoice type body");      invoicetype originalitem = db.invoicetypes.firstordefault(x => x.id == id);      if (originalitem == null || originalitem.id != id)     {         item.id = 0;         post(item);     }      invoicetype namematchitem = db.invoicetypes.firstordefault(x => x.name == item.name);     if (namematchitem != null && namematchitem.id != item.id)         return request.createerrorresponse(httpstatuscode.conflict, "you can't have more 1 record same name");      if (modelstate.isvalid && id == item.id)     {         try         {             item.id = id;             objecthelper.copypropertyvalues(item, originalitem);             db.invoicetypes.applycurrentvalues(originalitem);             db.savechanges();         }         catch (dbupdateconcurrencyexception)         {             return request.createresponse(httpstatuscode.notfound, "record not found");         }         catch (exception ex)         {             string c = ex.message;         }          return request.createresponse(httpstatuscode.ok, "update successful");     }     else     {         return request.createerrorresponse(httpstatuscode.badrequest, "could not save database.");     } } 

here's web page controller code

[httppost] public actionresult editdata(string oper, int? id, string name, datetime? datecreated, int? active) {     invoicetypemodel cn = new invoicetypemodel();     switch (oper)     {         case "add":         {             cn.id = 0;             cn.name = name;             cn.datecreated = datetime.now;             cn.updatedby = user.identity.name;             cn.active = true;             _invoicetyperepository.create(cn);             return content("true");         }         case "del":         {             _invoicetyperepository.delete((int) id);             return content("true");         }         case "edit":         {             cn.id = (int) id;             cn.name = name;             cn.datecreated = (datetime) datecreated;             cn.dateupdated = datetime.now;             cn.updatedby = user.identity.name;             cn.active = active == 1;             _invoicetyperepository.upsert(cn);             return content("true");         }     }     return content("false"); } 

here's partial screenshot of edit form after receives error. it's correct information, 409 conflict formatting not happening properly.

enter image description here


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -