0

I am saving data into SQL Server using jQuery Ajax through MVC and i am passing json data. When my data is small then it is working fine but when my json contains large data it is saying Internal server error at the time of hitting $.ajax();

Here is my code (_dr is the object of another class(which is saving data into database throgh EF))

var dto = {
    'ob': ob
};
$.ajax({
    url: "/Recieve/Create",
    dataType: "json",
    contentType: "application/json; charset=utf-8",
    type: "POST",
    beforeSend: function () {
        link.addClass('loading');
    },
    data: JSON.stringify(dto),
    success: function (msg) {
        link.removeClass('loading');
        if (msg != null) {
            if (msg.URL == "/Error") {
                if (msg.dublist != "") {
                    noty({
                        text: "Item SrNo" + msg.dublist + " with same vendor already exist/Please Check Values...",
                        type: "error"
                    });


                    var data = msg.dublist.split(',');
                    for (var k = 0; k < data.length; k++) {

                        for (var xy = 0; xy < $("#Details tbody tr").length; xy++) {
                            var y = $("#iFromNo", xy).val();
                            if (y == data[k]) {
                                $("#Details tbody tr," + xy + " ").css("background-color", "red");
                                //$('tr:nth-child(odd)').addClass('odd');
                            } else {
                                $("#Details tbody tr," + xy + " ").css("background-color", "yellow");
                            }
                        }
                    }

                } else {
                    noty({
                        text: "Error Occured..",
                        type: "error"
                    });
                }
            } else {
                window.location = msg.URL;
            }
        }
    }
});


public JsonResult Create(RecieveViewModel ob) {
    string path = "/Error";
    string duplicateItems = "";
    int finalRecId = 0;
    try {
        var centerId = SessionWrapper.Account == null ? "" : SessionWrapper.Account.DefaultCenterId == null ? "" : SessionWrapper.Account.DefaultCenterId;
        var createdby = SessionWrapper.Account == null ? "" : SessionWrapper.Account.UserName == null ? "" : SessionWrapper.Account.UserName;
        if (ob.Details.Count() > 0 && centerId.Length > 0) {
            //updated on 26th dec 2012
            finalRecId = _dr.SaveReceiveMasterAndDetails(ob, out duplicateItems);
            if (finalRecId > 0) {
                var sessionid = string.Empty;
                if (HttpContext.Session != null) sessionid = HttpContext.Session.SessionID;

                _dr.DeleteTempBySession(sessionid);

                path = Url.Action("Index");
            }
        } else {
            path = "/Error";
        }
    } catch (Exception ex) {
        path = "/Error" + ex.Message;
    }
    return Json(new {
        URL = path,
        dublist = duplicateItems
    }, JsonRequestBehavior.AllowGet);
}
tereško
  • 58,060
  • 25
  • 98
  • 150
CY_Techie
  • 86
  • 7
  • 1
    There is an issue with content length. check this answer and configure your web config accordingly http://stackoverflow.com/questions/3853767/maximum-request-length-exceeded – Priyank Aug 29 '14 at 10:23
  • In your position I would use Fiddler to determine the underlying error being thrown by MVC. If you look at the response being returned, you can usually find a fairly clear error message. – Ann L. Aug 31 '14 at 16:57
  • WhenI debug the same on my machine then no error occured. It comes out only when I upload my dll – CY_Techie Sep 02 '14 at 06:10

0 Answers0