This project is read-only.

Creating a new Html Helper Extension in Orchard

Topics: Customizing Orchard, Writing modules
Oct 11, 2012 at 11:31 AM
Edited Oct 11, 2012 at 11:50 AM

Hi Folks,

I have created a Html Helper Extension for use with multiple forms (named validation summary), which can be used in razor as follows:


@using Bede.GRMS.Mvc.HtmlHelpers;


@Html.NamedValidationSummary("logon", T("Login was unsuccessful. Please correct the errors and try again.").ToString())


It is in a reference dll called Cool.Mvc which is included in my module (as a file based reference, rather than a project reference, due to recent painful experience I'm fully aware that module packaging doesn't respect project references)

When I run my Orchard project in Visual studio everything is fine and dandy, and the html helper is found and respected. It works correctly

When I package the module, and consume it in a Web Matrix Orchard site however, I get the classic


 CS0246: The type or namespace name 'Cool' could not be found (are you missing a using directive or an assembly reference?)


(yes, it is stuck on the first part of the namespace).

Checking the contents of my .nupkg module package (by turning it into a zip file) i can see:

  1. My Cool.Mvc.dll file is in the bin folder for the module
  2. Once I install the module in my web matrix run site, I can see the dll in the dependencies folder, so this appears to have been a successful module deployment


I have also tried various combinations of updating web.configs (root and individual module) with 

    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <pages pageBaseType="Orchard.Mvc.ViewEngines.Razor.WebViewPage">
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
		<add namespace="System.Web.WebPages" />
        <add namespace="System.Linq"/>
        <add namespace="System.Collections.Generic"/>
        <add namespace="Orchard.Mvc.Html"/>
          <add namespace="Cool.Mvc"/><!--my namespace here-->


If I was to directly drop my Cool.Mvc.dll into the root bin folder of the web matrix project then all is well and everything works. Unfortunately, I know that is not what Orchard does. I'm wondering why Orchard does not check the dependencies folder for this dll when rendering razor views when it appears to do so for all other types of code. Is there something I'm missing, or is this a bug in Orchard?



Oct 11, 2012 at 4:46 PM

The web.config in modules is irrelevant I'm afraid. Only VS will pay attention to it, as far as I'm aware. It seems to be a limitation that razor assemblies come from the top web.config. So I'm guessing you can use your helpers all you want from your compiled code but not from the views? If you can confirm that is the case, I think you should file a bug for this. As a (bad) workaround, you could proxy your helper dll's code from the module's code, as that will be accessible from your views, or you could add the assembly to the top web.config manually (which is probably worse).

Oct 11, 2012 at 6:12 PM

Hi Bertrand,

changing web.config values does change the precise error message I'm getting, but the end result is the same - the dll needs to be in the root Orchard bin folder before it is respected by the views. I'm pretty certain that there was no issue with the helpers from within compiled code, but I can confirm that tomorrow morning once back in the office (I'm UK based). Proxying the calls might work, but adding the the assembly to the top web.config didn't work.



Oct 12, 2012 at 9:54 AM

I've confirmed that calls within compiled code were working correctly. I will file a bug for this.