JqGrid generates server checks and user error messages

I have an editable grid with a toolbar in which there are buttons for editing and adding entries.

  • I would like to use server side validations from my asp.mvc to display validation messages in jqgrid edit form. (is it possible?)
  • I would like to override the message (Internal server Error ...) in the edit form when an exception occurs in the application. (this should be possible, but I just can't figure out how to do this, perhaps using errorTextFormat, but how?)

Can someone provide an example?

+2
source share
1 answer

, errorTextFormat - HTTP .

, HTTP HTTP. errorTextFormat prmEdit, prmAdd, prmDel navGrid jqGrid (. ). errorTextFormat jQuery.jgrid.edit jQuery.jgrid.del. , .

errorTextFormat . ASP.NET MVC WFC , JSON ( throw new WebFaultException<string> ("my error text", statusCode);, ), - HTML-. errorTextFormat , . :

my.errorTextFormat = function (data) {
    var str = data.responseText.substr(0, 1);
    var str1 = data.responseText.substr(0, 6).toLowerCase();
    if (str === '"') {
        var errorDetail = jQuery.parseJSON(data.responseText);
        var s = "Fehler: '";
        s += data.statusText;
        s += "'. Details: ";
        s += errorDetail;
        return s;
    }
    else if (str1 === "<html " || str1 == "<html>" ||
             data.responseText.substr(0, 169) === '<?xml version="1.0" encoding="utf-8"?>\r\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r\n<html ') {
        var bodyHtml = /<body.*?>([\s\S]*)<\/body>/.exec(data.responseText)[1];
        return bodyHtml; //bodyContents1;
    }
    else {
        var res = "Status: '";
        res += data.statusText;
        res += "'. Felhercode: ";
        res += data.status;
        return res;
    }
};
jQuery.extend(jQuery.jgrid.edit, {
    ...
    errorTextFormat: my.errorTextFormat
});
jQuery.extend(jQuery.jgrid.del, {
    ...
    errorTextFormat: Testportal.errorTextFormat
});

, .

+4

All Articles