LinkBuilder.BuildUrlFromExpression not working anymore in .Net 4 / VS 2010?
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 :
is there a better way now to build links from an expression ? (yes I tried to google it without success)
is there a trick 开发者_JS百科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...
Our team overcame this identical issue by referencing System(Microsoft).Web.Mvc 2.0.0.0 statically in our libraries folder, as opposed to a GAC reference. This permitted us to continue working with MVC 1.0.0.0 projects and also gave us the downstream benefit of not having to install MVC 2 on our servers.
Oki, I found the problem.
I had assemblies versioning problems. After rebuilding Microsoft.Web.Mvc + unistalling MVC 1 + refreshing all references it finally worked again.
It sucks because I still need MVC 1 for others projects, but at least my main problem has been solved.
To developpers new to the MVC framework : consider starting directly with MVC 2 / VS.Net 2010 / C# 4.0
精彩评论