Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I focus input element on Asp.Net Core (MVC6) view

Do You know of a way to add focus to an input element on a razor view for Asp.Net Core. I know this can be done via javascript, but is there a tag for that as well? Either on the input element or the containing form element.

Thanks in advance

Søren Rokkedal

like image 600
Søren Rokkedal Avatar asked Jul 16 '16 19:07

Søren Rokkedal


1 Answers

You can do this:

<input type="text" name="name" autofocus>

Or

@Html.TextBox("name", null, new { autofocus = "autofocus" }) 

Or

<input asp-for="name"  autofocus/>
like image 97
enet Avatar answered Nov 01 '22 09:11

enet