LinkBuilder.BuildUrlFromExpression not working anymore in .Net 4 / VS 2010 ?

Posted by Mose on Stack Overflow See other posts from Stack Overflow or by Mose
Published on 2010-02-24T12:38:05Z Indexed on 2010/04/08 0:33 UTC
Read the original article Hit count: 1367

Filed under:
|

Hi,

I recently migrating my ASP.Net MVC 1 application from VS.Net 2008 / C# 3.5 to VS.NET 2010 / C# 4.0.

I massively used a builder to get URL strings from the strongly typed calls. It looks like this :

// sample call :
string toSamplePage = Url.To<SampleController>(c => c.Page(parameter1, parameter2));

the code is added as an extension to the default UrlHelper :

public static string To<Tcontroller>(UrlHelper helper, Expression<Action<Tcontroller>> action) where Tcontroller : Controller
{
    // based on Microsoft.Web.Mvc.dll LinkBuilder
    return LinkBuilder.BuildUrlFromExpression<Tcontroller>(helper.RequestContext, helper.RouteCollection, action);
}

The only problem of this, is the reference to Microsoft.Web.Mvc dll, but the gain in readability was worth it.

Problem : it does not work anymore, return (null) whatever the parameters.

Questions :

  1. is there a better way now to build links from an expression ? (yes I tried to google it without success)

  2. is there a trick to have the former LinkBuilder.BuildUrlFromExpression works ? I tried to recompile it into C# 4.0, but the problem is that it implies working on my own compilated version of System.Web.Mvc which is not an option.

I'm currently trying to migrate to MVC 2 but I still have issues... Waiting for your suggestions...

© Stack Overflow or respective owner

Related posts about asp.net-mvc-2

Related posts about .net-4.0