The name is pretty confusing probably. I have a requirement where a URL must be name friendly to represent dates (schedule/today
, schedule/tomorrow
etc). I don't want to clutter my route mappings with DateTime.Now
, DateTime.Now.AddDays(1)
etc for different parameters so I decided to create routes that map to an action of the same name:
routes.MapRoute(RouteNames.ScheduleToday, "schedule/today", new { controller = "Schedule", action = "Today" });
routes.MapRoute(RouteNames.ScheduleTomorrow, "schedule/tomorrow", new { controller = "Schedule", action = "Tomorrow" });
The idea for the actions is that I'd like to be able to call the Today()
action but actually call the List(DateTime date)
action with, for example, DateTime.Now
as the date
parameter.
This works great like this:
public ActionResult Today()
{
return this.List(DateTime.Now);
}
public ViewResult List(DateTime date)
{
this.ViewData["Date"] = date;
return this.View("List");
}
I'd like to be able to call this.View()
instead of this.View("List")
. Is this possible other than what I've posted above? It seems as though the view that is rendered matches the name of the first action that is called since the only way to get this to work is to explicitly render the List
view.