I have an HtmlHelper extension method that pulls in localized text from a database cache. The code is like this. (MVCWeb is the namespace of my MVC app.)
using System.Web;
using System.Web.Mvc;
namespace MVCWeb.PresentationExtensions
{
public static class HtmlHelperExtensions
{
public static HtmlString GetText(this HtmlHelper Html, string keyword)
{
// code to get the text based on the keyword
}
}
}
I am using @using MVCWeb.PresentationExtensions
in my Views. In ~/Views folder, calling the extension method is working perfectly.
I recently added an Area. I am using the extension method in the View files in the ~/Areas/AreaName/Views folder, and the code is compiling and it does work, however I am getting errors in the IDE.
Every time I use @Html.GetText("SomeKeyword")
from within the Area view, the following two errors are displayed on the errors list.
- 'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'GetText' and the best extension method overload 'MVCWeb.PresenationExtension.HtmlHelperExtensions.GetText(System.Web.Mvc.HtmlHelper, string)' has some invalid arguments
- Instance argument: cannot convert from 'System.Web.WebPages.Html.HtmlHelper' to 'System.Web.Mvc.HtmlHelper'
I've figured out that in ~/Views, @Html has the following code comments:
HtmlHelper<dynamic> WebViewPage<dynamic>.Html
Gets or sets the System.Web.Mvc.HtmlHelper object that is used to render HTML elements.
In ~/Area/AreaName/Views, @Html has these comments:
HtmlHelper WebPage.Html
Gets the System.Web.WebPages.Html.HtmlHelper object that is associated with a page.
For reference, my Web.config files in ~/Views and ~/Areas/AreaName/Views match. This is an MVC4 app on .NET 4.5 and hasn't been converted from a previous version of MVC.
- Is it normal that @Html is defined as different types in the regular Views vs area Views?
- Why is this compiling and running correctly if the IDE is showing errors? Is this an IDE bug?
- How can I stop these errors from showing in the IDE?