I have a Visitors controller. Inside I have Index and SignIn actions. Here are the actions:
public ActionResult Index(int month,
int day,
int year){
var visitors = visitorRepoistory.FindVisitorsByDate(month, day, year).ToList();
return View("Index", visitors);
}
[HttpPost]
public ActionResult SignIn(Visitor visitor) {
if (ModelState.IsValid) {
visitorRepoistory.Add(visitor);
visitorRepoistory.Save();
return RedirectToAction("/", new { month = DateTime.Now.Month, day = DateTime.Now.Day, year = DateTime.Now.Year });
} else {
return View(new VisitorFormViewModel(visitor));
}
}
More specifically, I'm trying to understand the RedirectToAction() in SignIn(). I would like to have it redirect to my index action and have the url look like: .../08/10/2010, but instead I get: ?month=8&day=10&year=2010. How can I fix this?
Thanks.
Update Here is my route (When hardcoded in the url it works):
routes.MapRoute(
"VisitorsByDate", // Route name
"{controller}/{month}/{day}/{year}", // URL with parameters
new { controller = "visitors", action = "index"}, // Parameter defaults
new { month = @"\d{2}", day = @"\d{2}", year = @"\d{4}" }
);