I would like to have an index action with an optional string parameter. I can not make it work.
I need the following routes:
http://mysite/download http://mysite/download/4.1.54.28
The first route will send the null model to the Index view, and the second will send the string with the version number.
How to determine the route and controller?
This is the definition of my route:
routes.MapRoute( name: "Download", url: "Download/{version}", defaults: new { controller = "Download", action = "Index", version = UrlParameter.Optional } ); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } );
And this is the controller:
public ActionResult Index(string version) { return View(version); }
Why is this not working? I am not an expert in ASP MVC, but this seems to be a very simple problem.
Error
- When I go to
http://mysite/downloads , it works fine - When I go to
http://mysite/downloads/4.5.6 , the controller is called correctly, and this parameter is passed correctly. But then it seems that the look was not found. This is the error I found:

source share