在 ActionResults 之间保存数据
Keeping data between ActionResults
我正在根据存储过程返回的数据填充列表,这首先出现在 SpecificArea ActionResult 中:
public ActionResult SpecificArea(ModelCallDetails call, int id = 0 )
{
ReturnSpecificAreas(call, id);
return PartialView("SpecificArea", listCallDetails);
}
显示列表时,每一行都是一个操作链接,它将数据发送到 SpecificAreaWorker:
[HttpGet]
public ActionResult SpecificAreaWorker(ModelCallDetails call, int id)
{
TempData["StringOfIds"] = StringOfIds;
ReturnSpecificAreas(call, id);
if (ResponseMessage == "Successful")
{
return PartialView("SpecificArea", listCallDetails);
}
else
{
return RedirectToAction("ViewCall");
}
}
我想收集被单击的每一行的 ID,并将它们存储在模型的列表中,以便我可以创建一个 ID 字符串。但是,每次单击 table 中的一行时,它都会刷新模型,我不再有 ID 列表了。
public void ReturnSpecificAreas(ModelCallDetails call, int id)
{
SelectedAffectedServiceID = id;
call.AffectedServiceList.Add(SelectedAffectedServiceID);
foreach (int item in call.AffectedServiceList)
{
if (TempData["StringOfIds"] != null)
{
StringOfIds = TempData["StringOfIds"].ToString();
StringOfIds += string.Join(",", call.AffectedServiceList.ToArray());
}
else
{
StringOfIds += string.Join(",", call.AffectedServiceList.ToArray());
}
}
我已尝试在临时数据中保存数据,但无法执行此操作 - 每次单击操作链接时临时数据都会刷新吗?有没有更好的方法来实现这个?
我相信您使用的是 MVC5?如果是这样,请使用
System.Web.HttpContext
这获取当前请求
保存....
System.Web.HttpContext.Current.Application["StringOfIds"] = StringOfIds; //Saves global
System.Web.HttpContext.Current.Session["StringOfIds"] = StringOfIds; //Saves Session
要检索...
StringOfIds = (string) System.Web.HttpContext.Current.Application ["StringOfIds"]; //Retrieves from global memory
StringOfIds = (string) System.Web.HttpContext.Current.Session ["StringOfIds"]; //retrieves from session memory
祝你好运。
我正在根据存储过程返回的数据填充列表,这首先出现在 SpecificArea ActionResult 中:
public ActionResult SpecificArea(ModelCallDetails call, int id = 0 )
{
ReturnSpecificAreas(call, id);
return PartialView("SpecificArea", listCallDetails);
}
显示列表时,每一行都是一个操作链接,它将数据发送到 SpecificAreaWorker:
[HttpGet]
public ActionResult SpecificAreaWorker(ModelCallDetails call, int id)
{
TempData["StringOfIds"] = StringOfIds;
ReturnSpecificAreas(call, id);
if (ResponseMessage == "Successful")
{
return PartialView("SpecificArea", listCallDetails);
}
else
{
return RedirectToAction("ViewCall");
}
}
我想收集被单击的每一行的 ID,并将它们存储在模型的列表中,以便我可以创建一个 ID 字符串。但是,每次单击 table 中的一行时,它都会刷新模型,我不再有 ID 列表了。
public void ReturnSpecificAreas(ModelCallDetails call, int id)
{
SelectedAffectedServiceID = id;
call.AffectedServiceList.Add(SelectedAffectedServiceID);
foreach (int item in call.AffectedServiceList)
{
if (TempData["StringOfIds"] != null)
{
StringOfIds = TempData["StringOfIds"].ToString();
StringOfIds += string.Join(",", call.AffectedServiceList.ToArray());
}
else
{
StringOfIds += string.Join(",", call.AffectedServiceList.ToArray());
}
}
我已尝试在临时数据中保存数据,但无法执行此操作 - 每次单击操作链接时临时数据都会刷新吗?有没有更好的方法来实现这个?
我相信您使用的是 MVC5?如果是这样,请使用
System.Web.HttpContext
这获取当前请求
保存....
System.Web.HttpContext.Current.Application["StringOfIds"] = StringOfIds; //Saves global
System.Web.HttpContext.Current.Session["StringOfIds"] = StringOfIds; //Saves Session
要检索...
StringOfIds = (string) System.Web.HttpContext.Current.Application ["StringOfIds"]; //Retrieves from global memory
StringOfIds = (string) System.Web.HttpContext.Current.Session ["StringOfIds"]; //retrieves from session memory
祝你好运。