Is it possible to set the focus on the following code on a page load without the use of JavaScript?
<div class="col-md-10">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
Is it possible to set the focus on the following code on a page load without the use of JavaScript?
<div class="col-md-10">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
Your can use the autofocus
attribute. Refer documentation
@Html.TextBoxFor(model => model.Description, new { autofocus = "autofocus" })
The equivalent for EditorFor
(using MVC-5.1+ only) is obtained with the following syntax:
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { autofocus = "autofocus" } })
You can add id to your div and pass this id int the end of the url of your page:
<div class="col-md-10" id="description">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
http://site/page#description