Razor imported namespaces
I'm having issues with my extensions to the UrlHelper class as they are not being picked up. So far I've done the following:
1) Added the namespaces to the section in the web.config located in the Views folder. I've also added them into the main web.config to be sure.
<system.web.webPages.razor>
2) Made sure that the System.Web.Mvc reference in the csproj file is for MVC3. I've also made sure the System.Web.WebPages and System.Web.Helpers references are included.
3) Made sure that the csproj ProjectTypeGuids are correct.
{E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
4) Ch开发者_JAVA百科ecked that the bindingRedirect points to MVC3.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Am I missing anything as Google hasn't brought up anything different?
The code is as follows (with the non-relevant stuff stripped out):
namespace MyNameSpace.Controllers.Extensions
{
using System.Web.Mvc;
using System.Web.Routing;
using Contracts.Entities;
using Controllers.Routing;
public static class UrlHelperExtensions
{
public static string BrowseLink(this UrlHelper urlHelper, ICategory category)
{
var routeValueDictionary = new RouteValueDictionary
{
{ "categorypath", BrowsePath.Serialize(catagory) },
{ "pagenumber", "1" }
};
return urlHelper.Action("Index", "Browse", routeValueDictionary);
}
}
}
In the web.config under Views folder add to this :
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="NAMESPACE OF YOUR EXTENSION CLASS" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
And unload/ reload the project. If the problem persists simply use an @using directive on top your cshtml or vbhtml page and import your Extension class. By the way when you say "extensions to the UrlHelper" I understand you just have a static class with methods that have this UrlHelper helper
as the 1st argument. If this is the case use @using directive first to see if it works in cshtml then try adding to web.config
精彩评论