在执行一个操作时,在Controller操作之间共享数据

时间:2015-03-18 11:37:51

标签: ajax asp.net-mvc

在同一个控制器中执行操作:

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等。

干杯

0 个答案:

没有答案