gpt4 book ai didi

asp.net-mvc-3 - ASP.NET MVC3 - Html.TextBoxFor 和 autofocus 属性

转载 作者:行者123 更新时间:2023-12-03 10:48:53 26 4
gpt4 key购买 nike

如何生成以下 input使用标准 HTML 帮助程序和 Razor View 引擎的元素:

<input id="Foo" name="Foo" type="text" autofocus />

我可以使用标准的 HTML 帮助程序还是必须自己编写?

任何帮助将不胜感激!

最佳答案

您可以将其他 HTML 属性传递给 TextBoxFor方法:

@Html.TextBoxFor(m => m.Foo, new { autofocus="autofocus"})

编辑:
您只能获得 autofocus=""和:
@Html.TextBoxFor(m => m.Foo, new { autofocus=""})

所有内置的助手都在使用 TagBuilder类(class) MergeAttribute内部方法,它只支持以下格式的属性: key="value" .
所以如果你只需要 autofocus您需要使用自定义 html 构建器编写自己的帮助程序。

关于asp.net-mvc-3 - ASP.NET MVC3 - Html.TextBoxFor 和 autofocus 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8533053/

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