. , , ?
RAZOR/HTML:
<div>
@using (Html.BeginForm("Previous", "Home", new{ year = @year, month = @month }, FormMethod.Post))
{
<input id="previous" type="submit" value="Previous" />
}
@using (Html.BeginForm("Next", "Home", new { year = @year, month = @month }, FormMethod.Post))
{
<input id="next" type="submit" value="Next" />
}
</div>
/ :
public ActionResult Index(int? year = 2012 , int? month = 2)
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
Calendar monthEventsCal = new Calendar();
HTMLMVCCalendar.Models.MonthModel allMonthEvents = monthEventsCal.monthEvents(year.Value, month.Value);
return View("Index", allMonthEvents);
}
[HttpPost]
public ActionResult Previous(int? year = 2012, int? month = 2)
{
Calendar monthEventsCal = new Calendar();
var newMonth = monthEventsCal.previousMonth(year.Value, month.Value);
int currMonth = newMonth.Item2;
int currYear = newMonth.Item1;
return RedirectToAction("Index", "Home", new { month = currMonth, year = currYear });
}
[HttpPost]
public ActionResult Next(int? year = 2012, int? month = 2)
{
Calendar monthEventsCal = new Calendar();
var newMonth = monthEventsCal.nextMonth(year.Value, month.Value);
int currMonth = newMonth.Item2;
int currYear = newMonth.Item1;
return RedirectToAction("Index", "Home", new { month = currMonth, year = currYear });
}
Global.asax.cs:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{month}/{year}",
new { controller = "Home", action = "Index", month = UrlParameter.Optional, year = UrlParameter.Optional }
);
}