剃刀:声明HTML佣工 [英] Razor: Declarative HTML helpers
问题描述
我试图写一个简单的声明的HTML帮助:
I'm trying to write a simple declarative html helper:
@helper Echo(string input) {
@input
}
助手工作正常,如果我将它嵌入我想使用它的页面。但是,如果我将它移到一个单独的 .cshtml
文件,并将该文件中的〜/查看/助手
目录,我的看法可能由于助手不在发现不能再编译。据对剃刀斯科特谷的博客文章,它应该工作。
The helper works fine if I embed it into the page I want to use it on. But if I move it to a separate .cshtml
file and place that file in the ~/Views/Helpers
directory, my view can't be compiled anymore because the helper is not found. According to Scott Gu's blog article on Razor it should work.
我在做什么错了?
推荐答案
的〜/查看/助手
位置在ScottGu职位描述不会MVC 3 RTM工作。在时间文章写这是我们被折腾周围的设计理念,但最终我们没能实现它。
The ~/Views/Helpers
location as describe in that ScottGu post will not work in MVC 3 RTM. At the time that article was written it was a design idea we were tossing around but ultimately we were not able to implement it.
把你的助手在APP_ code的作品,但具有一定的局限性影响某些MVC场景(例如:以标准的MVC没有访问 HTML
佣工)
Putting your helpers in App_Code works but has certain limitations that impact certain MVC scenarios (for example: no access to standard MVC Html.
helpers)
这篇关于剃刀:声明HTML佣工的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!