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

1

9

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

Polypary answered 16/7, 2016 at 19:45 Comment(0)
S
16

You can do this:

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

Or

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

Or

<input asp-for="name"  autofocus/>
Sarasvati answered 17/7, 2016 at 13:56 Comment(1)
Thank for the answer. That works as expected in Chrome and IE.Coper

© 2022 - 2024 — McMap. All rights reserved.