In my ASP.NET MVC 4 application, RouteConfigI registered the following default route:
routes.MapRoute("Default", "{controller}/{action}/{id}",
new { controller = "home", action = "index", id = UrlParameter.Optional });
Now, in Razor views, I want to create a URL for my application root as follows:
<a href="@Url.Action("index", "home")">Home</a>
The generated URL contains a trailing slash; clicking on the link opens the localhost / IISApplicationName / page. However, I want the URL not to contain the trailing slash, so that the URL is localhost / IISApplicationName. Creating routes for other activities, such as / Account / Login, does not create URLs with trailing slashes — it's just the route associated with my application root.
Is there a way to prevent ASP.NET MVC routing from adding a trailing slash to the above route?
(I know that I can redirect the URL, including the slash, without it, but I would rather have the router generate the correct route URL in the first place.)
source
share