I've seen some articles (even MSDN) suggest TempData for passing data between ActionMethods. But I've seen others here say that TempData should be avoided. What's the best practices way to approach this?
Here's some code to show my situation. Note: I'm 100% sure, I'm doing this wrong. Which is why I'm here. :) Also, I've been doing Webforms up until recently.
Note2: This is related, but not the same.
View:
<div>
@using (Html.BeginForm("Previous", "Home", new {month = @month}, FormMethod.Post))
{
<input id="previous" type="submit" value="Previous" />
}
// This fails but that's another situation
@using (Html.BeginForm("Next", "Home", new {month = @month, year = @year}, FormMethod.Post))
{
<input id="next" type="submit" value="Next" />
}
</div>
Controller methods:
[HttpPost]
public ActionResult Previous(HTMLMVCCalendar.Models.MonthModel prevMonth)
{
Calendar monthEventsCal = new Calendar();
int month = prevMonth.Month;
int year = prevMonth.Year;
var newMonth = monthEventsCal.previousMonth(year, month);
month = newMonth.Item2;
year = newMonth.Item1;
return RedirectToAction("Index", "Home", new { month = month });
}
[HttpPost]
public ActionResult Next(HTMLMVCCalendar.Models.MonthModel nextMonth)
{
Calendar monthEventsCal = new Calendar();
int month = nextMonth.Month;
int year = nextMonth.Year;
var newMonth = monthEventsCal.nextMonth(year, month);
month = newMonth.Item2;
year = newMonth.Item1;
return RedirectToAction("Index", "Home", new { year = year, month = month });
}