When I use a form to call a method on the controller, I want the page to refresh, and the url to sho

Posted by MedicineMan on Stack Overflow See other posts from Stack Overflow or by MedicineMan
Published on 2010-04-15T08:04:11Z Indexed on 2010/04/15 8:13 UTC
Read the original article Hit count: 465

Using ASP MVC, I have set up a webpage for localhost/Dinner/100 to show the dinner details for dinner with ID = 100.

On the page, there is a dropdown that shows Dinner 1, Dinner 2, etc. The user should select the dinner of interest (Dinner 2, ID = 102) off the form and press submit. The page should refresh and show the url: localhost/Dinner/102, and show the details of dinner 2.

My code is working except for the url. During this, my url shows localhost/Dinner/100 even though it is correctly displaying the details of Dinner 2 (ID = 102).

My controller method is pretty simple:

    public ActionResult Index(string id)
    {
        int Id = 0;
        if (!IsValidFacilityId(id) || !int.TryParse(id, out Id))
        {
            return Redirect("/");
        }

        return View(CreateViewModel(Id));
    }

can you help me figure out how to get this all working?

p.s. I did create a custom route for the method:

routes.MapRoute(
            "DinnerDefault",                         // Route name
            "Dinner/{id}",                           // URL with parameters
            new { controller = "Dinner", action = "Index", id = "" }  // Parameter defaults
        );

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about web-development