views:

15

answers:

1

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}" }
        );
A: 

Do you have a route that matches these values to route values? If you do not have a matching route, .NET MVC will show your parameters in the old school(??) format and not within a nice path like /home/blog/8/10/2010

routes.MapRoute("Visitor_Routes",  
                "{controller}/{action}/{month}/{day}/{year}", 
                new {  
                      controller = "Blog", 
                      action = "archive", 
                      year = Urlparameter.Optional, 
                      month = Urlparameter.Optional, 
                      day = Urlparameter.Optional
                    }); 
Tommy
My route looks like this and when hardcoding the url it works the way it should: 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{24}" } );
Beavis
Oops. I updated the original post with my route.
Beavis
Ah...turns out that my month (DateTime.Now.Day) is only a single integer and that's why the route wasn't getting picked up. Thanks!
Beavis