I want to create a Razor helper to cut down on on the amount of code I need to write. I added an App_Code folder to my project and added a file called MyHelpers.cshtml, with the following contents (trivial example for the purposes of illustration)...
@using System.Web.Mvc
@using System.Web.Mvc.Html
@helper HomeLink() {
@Html.ActionLink("Home", "Index", "Home")
}
However, this gives a compiler exception, saying there isn't an overload for Html.ActionLink that takes three strings. The ActionLink code was copied from a Razor page where it works fine. I get similar problems when trying to use any of the other standard helpers inside my own helper.
If I try to use the MVC wrappers for Telerik's KendoUI, which are referenced like @Html.Kendo.ComboBox... then I get a red line under the Html with a message "Cannot convert instance type System.Web.WebPages.Html.HtmlHelper to System.Web.Mvc.HtmlHelper"
According to the note at the end of this blog post, this was a known issue with MVC3, but was supposed to be added in the next release...
http://weblogs.asp.net/scottgu/asp-net-mvc-3-and-the-helper-syntax-within-razor
According to this UserVoice page, the issue was actually fixed in VS2013...
I'm using VS2013 Update 4, in a brand new MVC5 project, and it doesn't seem to work. I've tried quite a few of the workarounds I found here, but none helped.
Anyone any ideas?