Jan 28, 2009 03:57 AM|molesinski|LINK
I am pretty sure RC introduced a bug in UrlHelper url generation code when working with ajax calls, because it tries to convert virtual path to client url by using async request path, which might be different (usually is, if executed action is on different
controller) than original view path. This results with generated url strings being relative to async request path, not the original referer path, which renders them invalid in view that requested async operation.
At the moment I use this method to filter all generated urls and convert them to absolute, if they are ajax requests.
string RootAjaxRequest(HttpRequestBase request, string relativeUrl)
var path = VirtualPathUtility.GetDirectory("~" + request.Path);
var absoluteUrl = "/" + VirtualPathUtility.MakeRelative("~/", path + relativeUrl);
Seems like there is no other workaround this bug right now as GenerateUrl is private method of UrlHelper and cannot be modified or called directly to prevent virtual path convertion to client relative path via passing useResolutionService parameter as false,
unless you construct Url with overloaded member accepting protocol and hostName arguments (which casuse GenerateUrl to skip convertion to client relative), but thats really not a real solution aswell.