How can I set focus on “Amount” textbox on page load for the following Razor code in MVC3?
<tr>
<th>
<div class="editor-label">
@Html.LabelFor(model => model.Amount)
</div>
</th>
<td>
<div class="editor-field">
@Html.EditorFor(model => model.Amount)
@Html.ValidationMessageFor(model => model.Amount)
</div>
</td>
</tr>
You could provide an additional class to the containing div:
and then you could use a jQuery class selector:
This being said you seem to have multiple
Amounttexboxes in a table and obviously only one can have the focus at a time. So assuming you want this to be the first, you could do this: