Jquery 使用Ajax和MVC保存数据
我通过MVC使用jQueryAjax将数据保存到SQLServer中,并传递json数据。当我的数据很小时,它工作正常,但当我的json包含大数据时,它在命中$.ajax时表示内部服务器错误 这是我的代码,dr是另一个类的对象,它通过EF将数据保存到数据库中Jquery 使用Ajax和MVC保存数据,jquery,asp.net-mvc,sql-server-2008,Jquery,Asp.net Mvc,Sql Server 2008,我通过MVC使用jQueryAjax将数据保存到SQLServer中,并传递json数据。当我的数据很小时,它工作正常,但当我的json包含大数据时,它在命中$.ajax时表示内部服务器错误 这是我的代码,dr是另一个类的对象,它通过EF将数据保存到数据库中 var dto = { 'ob': ob }; $.ajax({ url: "/Recieve/Create", dataType: "json", contentType: "application/jso
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);
}
内容长度存在问题。检查这个答案,并在您的位置相应地配置您的web配置。我将使用Fiddler来确定MVC抛出的底层错误。如果查看返回的响应,通常会发现一条相当清晰的错误消息。如果在我的计算机上调试相同的消息,则不会发生错误。只有当我上传我的dll时,它才会出现