Here are my ActionResult methods :
[HttpGet]
public ActionResult Index(string cityID, string numbers, int days, bool onlySpecial)
{
LastTwoParameters lastTwoParameters = new LastTwoParameters();
lastTwoParameters.listCities = Common.GetDropDownCitiesList();
lastTwoParameters.listLastTwoResult = new List<getReport_LastTwo_Result>();
// if IsPostBack , then execute
if (!string.IsNullOrEmpty(cityID) && days > 0)
{
using (KQXS context = new KQXS())
{
lastTwoParameters.listLastTwoResult = context.getReport_LastTwo(cityID, numbers, days, onlySpecial).ToList();
}
}
return View(lastTwoParameters);
}
[HttpPost]//Run action method on form submission
public ActionResult Index(List<Cities> listCities, string cityID, string numbers, int days, bool onlySpecial)
{
return RedirectToAction("Index", "LastTwo", new{cityID = cityID, numbers = numbers, days = days, onlySpecial = onlySpecial});
}
What I need is to detect if the page is called from a RedirectToAction method. Because I don't have the need to calculate the result the first time the user open the page.
There are two ways to resolve your issue.
You could use service side caching. Controller has TempData property. Simply set to the TempData["wasRedirected"] = true. And after your first read from the framework will clear the value. In your case TempData["wasRedirected"] == null means that your code was not redirected.
You could use url params for example you action:
public ActionResult Index(bool? wasRedirected)
{
return View();
}
And in redirect method you will have code like this:
[HttpPost]
public ActionResult Redirect()
{
return this.RedirectToAction("Index", new { wasRedirected = true });
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With