I have the following ActionLink
:
@Html.ActionLink("Upload", "Upload", "File")
yet when I hover over the link, the url displayed in the browser is http://localhost:44334/Upload
. Where is the controller in this url? Strangely, clicking the url takes me to my File/Upload
view, and yet stranger, the url displayed in the browser's address bar is https://localhost:44334/Upload
.
The ActionLink
is on page Home/Explorer
, so AFAIK a controller name is normally necessary.
Why is the ActionLink
helper leaving out the controller name, and why is the link still working? I have tried refreshing the page with cache clearing, with no difference. I don't know what else do besides leave it alone because it works, but I'm concerned this is some quirk and it will no longer work when I deploy my site.
My routing is still standard, out-of-box, in the Startup
class's Configure
method:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
Strangely enough, I have now added a Download
link each row of an HTML table of files, looking like this:
@Html.ActionLink("Download", "Download", "File", new { filePath = file.Path })
and this link also renders without the controller name, e.g:
https://localhost/Download?filePath=....
RouteConfig
it's difficult to tell if the route definition or route order is wrong. It is possible that a route defined without controller name in URL but has default values to controller and action name parameter. – Austinurl: "Upload"
withdefaults: new { controller = "File" ...}
(or the equivalentRouteAttribute
) – CrotonUpload
route defined, as explained in the edited question. – Lax