Have a web api doing crud, and a mvc front end. In front end controller, this is the edit code for jqgrid:
[HttpPost]
public JsonResult EditRecipientActivity(RecipientActivity model)
{
var result = HttpStatusCode.BadRequest;
if (ModelState.IsValid)
{
if (model.ActCount > 0)
{
var response = repo.SaveUpdatedRecipientActivity(model);
if (!response.IsSuccessStatusCode)
{
result = HttpStatusCode.BadRequest;
}
else
{
result = HttpStatusCode.OK;
}
return Json(result, JsonRequestBehavior.AllowGet);
}
else
{
var response = repo.AddRecipientActivity(model);
return Json(response.IsSuccessStatusCode, JsonRequestBehavior.AllowGet);
}
}
return Json(false, JsonRequestBehavior.AllowGet);
}
I am trying to pass the server error from the web api through to the jqgrid, so the message appears on the edit form.
With eh this code I can send just a status code to the form, but the actual status in the header is 200, even if the controller is returning a 400. How do I pass the actuall status code to the form?
EDIT: Changed the controller method. I can't use Request.CreateResponse, I'm guessing because this is not an API controller:
[HttpPost]
public HttpResponseMessage EditRecipientActivity(RecipientActivity model)
{
var response = repo.SaveUpdatedRecipientActivity(model);
return response;
}
This is the result sent to the web page:
StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Pragma: no-cache X-SourceFiles: =?UTF-8?B?QzpcX1ZTX1Byb2plY3RzXHRlc3RcU0ZBQVJfU1ZDXFNGQUFSX1NWQ1xyZWNpcGllbnRcdXBkYXRlYWN0aXZpdHlcMTIzMTIzMTIz?= Persistent-Auth: true Cache-Control: no-cache Date: Wed, 02 Sep 2015 16:44:13 GMT Server: Microsoft-IIS/8.0 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Content-Length: 2378 Content-Type: application/json; charset=utf-8 Expires: -1 }
This is what I was hoping, but it didn't trigger the jqGrid error message. Any idea why?
EDIT 2: Here is the navGrid code:
$("#activity-grid").jqGrid('navGrid', '#grid-pager',
{ edit: true, add: true, del: false, search: true, refresh: true },
{ //edit parameters
editData: { FV: fv, RecipKey: recipientId },
beforeShowForm: function (form) { $("#tr_ActCount", form).hide(); }, // Hides the ActCount field from the modal form
closeAfterEdit: true
},
{ //add parameters
editData: { FV: fv, ActCount: 0 },
beforeShowForm: function (form) { $("#tr_ActCount", form).hide(); }, // Hides the ActCount field from the modal form
closeAfterEdit: true
}