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);
}