I have an ASP.NET MVC3 application where my action generates a list of identifiers that I want to make available for a subsequent AJAX request. This means that I can run a long process in the background and poll it. The list of identifiers is a necessary contribution to this lengthy process. I do not want to pass them to the URL as a parameter, because the list can be very long and cause problems in IE.
My controller
public ActionResult Run() { List<MyObjs> objs = _db.MyObjs.ToList<MyObjs>(); string uniqueId = Guid.NewGuid().ToString(); ViewData["UniqueID"] = uniqueId; TempData["ObjIdList" + uniqueId] = String.Join(",", objs .Select(o => o.ObjID).ToArray<int>()); return View(objs); } public void StartProcess(string uid) { string ids = TempData["ObjIdList" + id].ToString().Split(','); ... }
My view
var uniqueId = '@ViewData["UniqueID"]'; $(document).ready(function (event) { $('#startProcess').click(function () { $.post("/Scheduler/StartProcess", { uid: uniqueId }, function () { getStatus(); }); event.preventDefault; }); }); function getStatus() { var r = new Date().getTime();
This works in my internal test, albeit on my laptop with one simultaneous user. Is it safe or is there a better way to transfer this data?
Paul
source share