是否可以在不使用JavaScript的情况下将重点放在页面加载上的以下代码上?
<div class="col-md-10">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
答案 0 :(得分:21)
您可以使用autofocus
属性。 Refer documentation
@Html.TextBoxFor(model => model.Description, new { autofocus = "autofocus" })
使用以下语法获得EditorFor
的等价物(仅使用MVC-5.1 +):
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { autofocus = "autofocus" } })
答案 1 :(得分:1)
您可以将ID添加到您的div,并将此ID传递到您网页的网址末尾:
<div class="col-md-10" id="description">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
http://site/page#description