@helper directive no longer works out of the box in ASP.NET5 MVC6 beta4.

拜拜、爱过 提交于 2019-12-08 15:40:05

问题


Since I updated my ASP.NET5 project to beta4 (the one included with Visual Studio 2015 RC), any of my Razor views where I use a helper, such as:

@helper foo()
{
   <h2>Bar</h2>
}

results in the following error:

error CS0103: The name 'helper' does not exist in the current context.

Is the @helper directive no longer supported? Can someone point me to anything useful about the issue?


回答1:


The @helper directive was removed since beta 4 because it imposed too many restrictions on other Razor features: https://github.com/aspnet/Razor/issues/281.

Edit
To be clear: based on the discussion in the GitHub issue(s) Microsoft is not planning to bring the @helper directive back or replace it in ASP.NET Core.




回答2:


Rather than using a helper method, you can achieve the same functionality using a partial with a view model. Just pass the relevant arguments into the Html.Partial command.



来源:https://stackoverflow.com/questions/29970447/helper-directive-no-longer-works-out-of-the-box-in-asp-net5-mvc6-beta4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!