Comment activer la zone de texte «FacultyName» lors du chargement de la page pour le code Razor suivant

@Html.TextBoxFor(i => i.FacultyName, new { @class = "form-control", @placeholder = "Technician etc", @name = "txtfacultyname" }) @Html.ValidationMessageFor(i => i.FacultyName, "", new { @class = "error" })
@Html.TextBoxFor(i => i.EmailAddress, new { @class = "form-control", @placeholder = "[email protected]", @name = "txtemailaddress" }) @Html.ValidationMessageFor(i => i.EmailAddress, "", new { @class = "error" })
@Html.TextBoxFor(i => i.UserName, new { @class = "form-control", @placeholder = "abc etc", @name = "txtusername" }) @Html.ValidationMessageFor(i => i.UserName, "", new { @class = "error" })

Vous pouvez utiliser $('#FacultyName').focus()

J’ai un peu changé votre code juste pour vous montrer que ça marche.

 $(document).ready(function() { $('#FacultyName').focus() // This code will only run when the page is done loading/ready })