Is it possible to use C# 6.0's new "using static" notation inside of display helpers in App_Code in MVC 5?
I attempted to do so but it did not seem to like the syntax.
I created a static helper class to expose UrlHelper and HtmlHelper within App_Code. I was hoping to include it with the "using static" syntax in order to use the properties of the class as I would as if the file had a ViewPage base class.
@using static Example.Core.ViewHelper
@helper ExampleUsingUrl() {
@Url.Action("Index", "Home")
}
With a ViewHelper looking like this.
namespace Example.Core
{
public static class ViewHelper
{
public static HtmlHelper Html { get; } = new HtmlHelper(new ViewContext(), new ViewDataContainer());
public static UrlHelper Url => new UrlHelper(HttpContext.Current.Request.RequestContext, RouteTable.Routes);
}
public class ViewDataContainer : IViewDataContainer
{
public ViewDataDictionary ViewData
{
get
{
return new ViewDataDictionary();
}
set
{
}
}
}
}
Is this feature not available for views yet? I am using Visual Studio 2015, MVC 5, .NET 4.6.1 and C# 6.0.