我想在我的应用程序中自动关注编辑,但我似乎做不到。我已经成功地在文本框上使用了自动对焦,但是我想使用一个编辑器来保持我的应用程序看起来是通用的。
任何解决方案都将不胜感激,谢谢。
我的尝试:
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" }, autofocus = "" })发布于 2015-08-23 16:48:41
这是因为您使用的是EditorFor,而不是某些特定的东西,如TextBoxFor。
@Html.TextBoxFor(model => model.Name, new { htmlAttributes = new {
@class = "form-control" }, autofocus="autofocus"})也可以使用jQuery:
<div class="editor-field focus">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
$(function() {
$('.focus :input').focus();
});更新
正如您所知道的,TextBoxFor总是创建一个具有输入类型的文本框,但是EditorFor有点聪明,它根据属性的数据类型呈现标记。
发布于 2018-01-06 00:00:05
使用.Net Framework4.5和MVC 5,这对我来说是可行的:
@Html.EditorFor(model => model.Description, new {
htmlAttributes = new {
@class = "form-control",
autofocus = true
}
})发布于 2016-04-06 19:41:48
您将自动焦点属性放置在错误的位置。
@Html.EditorFor(model => model.Description,
new { htmlAttributes = new { @class = "form-control" }, autofocus = "" })试一试:
@Html.EditorFor(model => model.Description,
new { htmlAttributes = new { @class = "form-control", autofocus = "" } })https://stackoverflow.com/questions/32169014
复制相似问题