I have created a custom WebViewPage. That allows me to add a custom helper to the use in my Razor views:
public abstract class CompanyNameWebViewPage<TModel> : WebViewPage<TModel>
{
public override void InitHelpers()
{
base.InitHelpers();
CompanyName = new CompanyNameHtmlHelper<TModel>(this.Html);
}
public CompanyNameHtmlHelper<TModel> CompanyName { get; protected set; }
}
Using it in my Razor as such:
@CompanyName.Theme.Image("logo.png")
The problem is that CompanyName is both the name I really want to use for the HTML helper and the namespace our code goes in. So, in visual studio @CompanyName.Theme.etc resolves to my CompanyNameHtmlHelper.
However, at runtime I get the error:
The type or namespace name 'Theme' does not exist in the namespace 'CompanyName' (are you missing an assembly reference?)
From which it is obvious that CompanyName is now resolving to the namespace instead of the HtmlHelper.
Why does this happen? Why does Visual Studio allow me to do this when it's going to give me a runtime error? Are there any work arounds? It's really annoying to have to come up with some convoluted name instead of just the name of my company.