I have an HtmlHelper extension method that retrieves localized text from a database cache. The code is this. (MVCWeb is the namespace of my MVC application.)
using System.Web; using System.Web.Mvc; namespace MVCWeb.PresentationExtensions { public static class HtmlHelperExtensions { public static HtmlString GetText(this HtmlHelper Html, string keyword) {
I am using @using MVCWeb.PresentationExtensions in my views. In the ~ / Views folder, calling the extension method works fine.
I recently added an area. I use the extension method in the view files in the ~ / Areas / AreaName / Views folder and the code compiles and it works, however I get errors in the IDE.
Each time I use @Html.GetText("SomeKeyword") from the Area view, the following two errors appear in the error list.
- 'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for GetText and the best extension overload method. MVCWeb.PresenationExtension.HtmlHelperExtensions.GetText (System.Web.Mvc.HtmlHelper, string) 'has some invalid arguments
- Instance argument: cannot be converted from 'System.Web.WebPages.Html.HtmlHelper' to 'System.Web.Mvc.HtmlHelper'
I realized 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 the following 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 correspond. This is an MVC4 application on .NET 4.5 and has not been converted from a previous version of MVC.
- Is it normal that @Html is defined as different types in regular vs area views?
- Why is this compilation and work correctly if the IDE shows errors? Is this an IDE bug?
- How can I stop these errors from showing in the IDE?
source share