views:

165

answers:

2

Hi folks,

I'm converting one of our ASP.NET MVC application from 1.0 to 2.0.

This is code that is erroring :-

string virtualPath = HttpContext.Request.ServerName() +
    RouteTable.Routes.GetVirtualPath(
        new RequestContext(HttpContext, 
            RouteTable.Routes.GetRouteData(HttpContext)),
        ExpressionHelper.GetRouteValuesFromExpression<PostController>(
            c =>c.Details("Post-Title")))
        .VirtualPath;

Ok .. that's a lot of ugly code. So what's going on?

It looks like we're trying to get the virtual path of a route. The FULL path, that is. Further investing the reason, it's because this value is used in some Service code, which has no idea about MVC or websites, etc. It's independent from the View. It needs a virtualPath because it converts that to a TinyUrl (yeah, one of those url shortening services).

So ... how can I do this in ASP.NET MVC 2.0 (using VS2010 B2)?

What's the error message?

'ExpressionHelper' is an ambiguous reference between 'System.Web.Mvc.ExpressionHelper' and 'Microsoft.Web.Mvc.Internal.ExpressionHelper'

hmmm ......

A: 

I think you just need to qualify it, like so:

string virtualPath = HttpContext.Request.ServerName() + RouteTable.Routes.GetVirtualPath( new RequestContext(HttpContext, RouteTable.Routes.GetRouteData(HttpContext)), System.Web.Mvc.ExpressionHelper.GetRouteValuesFromExpression( c =>c.Details("Post-Title"))) .VirtualPath;

Shachar
Nope: - 'System.Web.Mvc.ExpressionHelper' does not contain a definition for 'GetRouteValuesFromExpression'
Pure.Krome
A: 

a "using directive" to create an alias to the namespace ?

using ExpressionHelper = Microsoft.Web.Mvc.Internal.ExpressionHelper;
Mark
Yep. That was it. I swear i tried that. i must have done System, twice.
Pure.Krome