I\'m using ASP.Net MVC. Here\'s my code snippets from a controller named Course:
public ActionResult List(int id)
{
var viewmodel.ShowUrl = Url.Action(\
I'm guessing in your routing, you're not specifying that id is an optional parameter. Here's the default route in a sample project.
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } //Parameter defaults
);
Note the inclusion of id = UrlParameter.Optional
. Without that, you'd get the behavior you're describing because it thinks the id is mandatory.
On a side note, if your Show action doesn't always have an id then it should be nullable or provide a default.
public ActionResult Show(int? id)
public ActionResult Show(int id = 0)
Otherwise you'll get an error when you try loading the url without the id parameter.