MVC 5 – Using Javascript to set focus to control, textbox, button, dropdown list upon loading of a Razor View

Let’s say you want to add focus to a button in your view. The first thing you need to do is add the id attribute to your control and give it a name such as id=”RefreshListButton”.

Next, in the jquery document ready section, add a jquery function that will set the focus.

 $('#RefreshListButton').focus(); 

 $(document).ready(function () Here is the complete function:

  <script type='text/javascript'>
$(document).ready(function () {           
$('#RefreshListButton').focus();       
});
</script>