I have a little app that initially requests a user id. This user id is then sent as a parameter to a stored procedure that returns values from a database. What I would like for this app to do is to refresh those same values every 30 seconds. My issue is that when I refresh, I lose the user id. Is there something simple that I’m missing here?
public ActionResult Report()
{
string operatorCode = Request.Form.GetValues("txtOperator")[0].ToString();
ViewBag.operatorName = (from e in db.employees
where e.operator_code == operatorCode
select e.name).Max().ToString();
ViewData["operatorCode"] = operatorCode;
var results = db.lex_sp_Select_Paintline_FinRew_Operator(operatorCode);
Response.AddHeader("Refresh", "10");
return View(results.ToList());
}
I think the main reason for the null value is due to the fact that you are trying to refresh an HttpPost, rather than a request (the refresh header is not intended for POSTS). I’d suggest as an alternative, that you change your process to be a request, which would result in only needing to change the invoking code (to a get) and changing the Report action to:
this should give you the desired result, tho at the expense of the action now being a get rather than a post. You could also store the operatorCode in Session (tho this may not scale very well). The final option that I can see, would be to run an ajax request on a setInterval() and use that process to send a POST to the controller action.