可以在不使用
JavaScript的情况下在页面加载时将焦点放在以下代码上吗?
<div class="col-md-10"> @Html.EditorFor(model => model.Description) @Html.ValidationMessageFor(model => model.Description) </div>
解决方法
您可以使用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" } })