I have this route set up:
routes.MapRoute(
"home3", // Route name
"home3/{id}", // URL with parameters
new {
controller = "home",
action = "Index",
id = UrlParameter.Optional } // Parameter defaults
);
But in my controller I don't know how to get the optional id parameter. Can someone explain how I can access this and how I deal with it being present or not present.
Thanks
your can write your actionmethod like
public ActionResult index(int? id)
{
if(id.HasValue)
{
//do something
}
else
{
//do something else
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With