I have this in my global
//custom route
routes.MapRoute(
"DownloadInstall", // Route name
"{controller}/{action}/{id}/{logonserver}", // URL with parameters
new { controller = "Software",
action = "DownloadInstall" } // Parameter defaults
);
//custom route
routes.MapRoute(
"DownloadHelp", // Route name
"{contr开发者_运维问答oller}/{action}/{id}/{logonserver}", // URL with parameters
new { controller = "Software",
action = "DownloadHelp" } // Parameter defaults
);
//default route
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Software", action = "Index",
id = UrlParameter.Optional } // Parameter defaults
);
and I invoke custom routes in javascript (which works great) like this:
window.location.href = '/Software/DownloadHelp/' + @Model.ID +'\/' +
getLogonServer();
However, as soon as I moved this to an IIS7 box which has a virtual directory, my default routes were smart enough to prepend with the virtual name...however my javascript based routes aren't found because the virtual directory isn't prepended.
I would try and use the Url
helper if I were you, but I realize the javascript function result will be a problem.
I'm not sure if that will work, but you could try and build up your link like this:
var server = getLogonServer();
window.location.href = '@Url.Action("DownloadHelp", "Software",
new { Model.Id, logonserver = ""})' + '/' + getLogonServer();
What definitely would work is making getLogonServer()
an Html helper function instead of a javascript function, but I don't know if that's an option for you.
I resolved it by using @Url.Content helper as such:
window.location.href = '@Url.Content("~/Software/DownloadInstall/")' + @Model.ID +'\/' + getLogonServer();
精彩评论