在同一个控制器中执行操作:
string vTotalRows = "0";
string vCurrentRow = "0";
[HttpPost]
public ActionResult Save(IEnumerable<HttpPostedFileBase> files)
{
vTotalRows = "100"; //it is getting set in loop
vCurrentRow = "1"; //it is getting set in loop
//Process takes some time here.. depend on how many records in the excel file
}
第二个动作功能如下:
public JsonResult GetUploadStatus()
{
string totalItems="?";
try
{
totalItems = vTotalRows;// Convert.ToString(TempData["TotalRows"]);
if (totalItems.Trim() == "") totalItems = "?";
}
catch { }
string currentItem = "?";
try
{
currentItem = vCurrentRow;// Convert.ToString(TempData["CurrentRow"]);
if (currentItem.Trim() == "") currentItem = "?";
}
catch { }
string result = string.Format("Uploading Item <b>{0}</b> of <b>{1}</b> - {2} of {3}", currentItem, totalItems, vCurrentRow, vTotalRows);
var jsonResult = Json(result, JsonRequestBehavior.AllowGet);
jsonResult.MaxJsonLength = int.MaxValue;
return jsonResult;
}
如果我通过ajax调用第二个函数,我对这两个变量总是得到0。尝试了TempData,ViewBag等。
干杯