【发布时间】:2018-10-09 05:15:31
【问题描述】:
我有一个调用特定方法的 Ajax 调用。
$.ajax({
url: '@Url.Action("ExcelDataUpload", "ProjectDefinition")',
type: "POST",
headers: { "cache-control": "no-cache" },
//data: { XLTransactionType: xltranstype, FilePath: filepath },
data: { XLTransactionType: xltranstype, ExcelUploadData: exceljsonData },
cache: false,
success: function (data) {
if (data != null && data.StatusID == 1) {
ShowMessage(1, data.Message);
}
else {
ShowMessage(0, data.Message);
}
},
error: function (data) {
ShowMessage(0, "Upload is not successful.Please try again!!!");
}
});
在这个方法内部使用事务作用域进行操作
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, TimeSpan.FromHours(1))) {
try {
using (objDb = new UPDEntities()) { }
}
if(id > 0) {
scope.Complete();
} else {
scope.Dispose();
}
}
这需要 3-4 分钟才能完成,但在 Ajax 调用完成之前,它总是返回错误消息,如果数据少则返回成功。如何暂停 Ajax 调用直到事务范围完成其操作?
【问题讨论】:
标签: ajax entity-framework model-view-controller transactionscope