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
);