gpt4 book ai didi

c# - 是否可以在自定义助手中使用 HtmlHelper 对象?

转载 作者:太空宇宙 更新时间:2023-11-03 22:19:38 26 4
gpt4 key购买 nike

是否有人可以建议是否可以在新的自定义 Html 帮助器中重新使用现有的 HtmlHelper。例如:

public static class GridHelper
{
public static string RenderGrid(this HtmlHelper helper, Object routeParams)
{
return HtmlHelper.BeginForm(routeParams);
}
}

上面是一个简单的例子,但本质上我想为一组渲染 View 的 html 助手分组一些逻辑和格式。这个 View 将在几个地方使用,因此我想重新使用代码。然而,在我目前的所有尝试中,我一直无法访问像“CheckBox”或“BeginForm”这样的方法。也许我没有正确使用 HtmlHelper 对象?

有谁知道这是否可以做到?

谢谢,马特

最佳答案

在您的示例中,我认为您需要执行以下操作:

public static class GridHelper 
{
public static string RenderGrid(this HtmlHelper helper, Object routeParams)
{
return helper.BeginForm(routeParams);
}
}

关于c# - 是否可以在自定义助手中使用 HtmlHelper 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3657205/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com