Мне удалось решить эту проблему в рамках одного действия, но я думаю, что это не так, как сказал Йохан. Я опубликую свое текущее решение ниже, если оно поможет кому-нибудь в будущем!
<input type="submit" method="index" value="Previous Week" class="btn btn-light" onclick="location.href = '@Url.Action("Index", "Appointment",new {state = 1,mon = ViewBag.monday, tues = ViewBag.tuesday,
wed = ViewBag.wednesday, thurs = ViewBag.Thursday, fri = ViewBag.friday, sat = ViewBag.saturday,
sun = ViewBag.sunday})'"/>
<input type="submit" value="Current Week" class="btn btn-light" onclick="location.href = '@Url.Action("Index", "Appointment",new {state = 0,mon = ViewBag.monday, tues = ViewBag.tuesday,
wed = ViewBag.wednesday, thurs = ViewBag.Thursday, fri = ViewBag.friday, sat = ViewBag.saturday,
sun = ViewBag.sunday})'"/>
<input type="submit" value="Next Week" class="btn btn-light" onclick="location.href = '@Url.Action("Index", "Appointment",new {state = 2,mon = ViewBag.monday, tues = ViewBag.tuesday,
wed = ViewBag.wednesday, thurs = ViewBag.Thursday, fri = ViewBag.friday, sat = ViewBag.saturday,
sun = ViewBag.sunday})'"/>
public IActionResult Index(int state, string mon, string tues, string wed, string thurs, string fri, string Sat, string sun)
{
//var mon
if (state <= 0)
{
ViewBag.monday = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek + (int)DayOfWeek.Monday).ToString("dd-MM-yyyy");
ViewBag.tuesday = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek + (int)DayOfWeek.Tuesday).ToString("dd-MM-yyyy");
ViewBag.wednesday = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek + (int)DayOfWeek.Wednesday).ToString("dd-MM-yyyy");
ViewBag.thursday = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek + (int)DayOfWeek.Thursday).ToString("dd-MM-yyyy");
ViewBag.friday = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek + (int)DayOfWeek.Friday).ToString("dd-MM-yyyy");
ViewBag.saturday = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek + (int)DayOfWeek.Saturday).ToString("dd-MM-yyyy");
ViewBag.sunday = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek + (int)DayOfWeek.Sunday + 7).ToString("dd-MM-yyyy");
return View();
}
else if(state == 1){
var pmon = Convert.ToDateTime(mon).AddDays(-7);
var ptues = Convert.ToDateTime(tues).AddDays(-7);
var pwed = Convert.ToDateTime(wed).AddDays(-7);
var pthur = Convert.ToDateTime(thurs).AddDays(-7);
var pfri = Convert.ToDateTime(fri).AddDays(-7);
var psat = Convert.ToDateTime(Sat).AddDays(-7);
var psun = Convert.ToDateTime(sun).AddDays(-7);
ViewBag.Monday = pmon.ToString("dd-MM-yyyy");
ViewBag.tuesday = ptues.ToString("dd-MM-yyyy");
ViewBag.wednesday = pwed.ToString("dd-MM-yyyy");
ViewBag.thursday = pthur.ToString("dd-MM-yyyy");
ViewBag.friday = pfri.ToString("dd-MM-yyyy");
ViewBag.saturday = psat.ToString("dd-MM-yyyy");
ViewBag.sunday = psun.ToString("dd-MM-yyyy");
return View();
}
else if (state == 2)
{
var pmon = Convert.ToDateTime(mon).AddDays(7);
var ptues = Convert.ToDateTime(tues).AddDays(7);
var pwed = Convert.ToDateTime(wed).AddDays(7);
var pthur = Convert.ToDateTime(thurs).AddDays(7);
var pfri = Convert.ToDateTime(fri).AddDays(7);
var psat = Convert.ToDateTime(Sat).AddDays(7);
var psun = Convert.ToDateTime(sun).AddDays(7);
ViewBag.Monday = pmon.ToString("dd-MM-yyyy");
ViewBag.tuesday = ptues.ToString("dd-MM-yyyy");
ViewBag.wednesday = pwed.ToString("dd-MM-yyyy");
ViewBag.thursday = pthur.ToString("dd-MM-yyyy");
ViewBag.friday = pfri.ToString("dd-MM-yyyy");
ViewBag.saturday = psat.ToString("dd-MM-yyyy");
ViewBag.sunday = psun.ToString("dd-MM-yyyy");
return View();
}
else
{
return View("NotFound");
}