Mvc 助手调用
我正在编写一些自定义助手,当前的助手涉及一种“数据网格控件”类型的助手,我似乎遇到了一些障碍。
如果我处于剃刀视图中,我可能会执行类似 Html.EditorFor(someExpression) 的操作,但我似乎找不到在自定义帮助程序中的帮助程序代码上下文中执行此操作的方法。
实际上,我正在尝试从助手内部调用助手。
这是我能想到的最基本形式的示例:
public static MvcHtmlString Test(dynamic Model)
{
return new MvcHtmlString( Html.textBox(Model.SomeProperty) )
}
有什么想法吗?
当我在代码中添加这样的 using 语句时,我发现这是多么愚蠢......
using Html = System.Web.Mvc.Html;
谈论简单......自我注意......注意框架!
I'm writing some custom helpers the current one involves a sort of "datagrid control" type helper and i seem to have hit a bit of a hurdle.
if i was in a razor view i coud something like Html.EditorFor(someExpression) and i can't seem to find a way to do that within the context of my helper code within my custom helper.
Effectively i'm trying to call a helper from within a helper.
Here's an example in the most basic form i can think of:
public static MvcHtmlString Test(dynamic Model)
{
return new MvcHtmlString( Html.textBox(Model.SomeProperty) )
}
Any ideas ?
I figured out how dumb this was when I added a using statement like this to my code ...
using Html = System.Web.Mvc.Html;
Talk about simple ... note to self ... pay attention to framework !!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将您的辅助方法改为扩展方法。
您可以通过首先使用方法所在的命名空间(类)来调用此方法,然后只需
Html.Test(Model)
Make your helper method into a extension method instead.
You call this by first have a using of the namespace where (the class where) the method is and then just
Html.Test(Model)