title: Submit on enter button keypress in cshtml
body: <p>Very new to MVC and trying to figure out how to attach a handler to a submit button so the user does not have to click the submit button.  </p>
  
  <p>I have the following JavaScript:</p>
  
  <pre><code>            //fix to add submit to the enter button
          function keypressHandler(e) {
              if (e.which == 13) {
                  e.preventDefault(); //stops default action: submitting form
                  $(this).blur();
                  $('#btnLoginSubmit').focus().click();//give your submit an ID
              }
          }
  
          $('#myForm').keypress(keypressHandler);
  </code></pre>
  
  <p>and here is the markup for the _Layout.cshtml page:</p>
  
  <pre><code>&lt;div ng-controller="LoginController"&gt;
  &lt;script type="text/ng-template" id="loginForm.html"&gt;
              &lt;div class="modal-header"&gt;
                  &lt;h3&gt;Please log in&lt;/h3&gt;
              &lt;/div&gt;
              &lt;form ng-submit="submit()"&gt;
                  &lt;div class="modal-body"&gt;
                      &lt;label&gt;User name&lt;/label&gt;
                      &lt;input type="text" ng-model="user.userId" /&gt;
                      &lt;label&gt;Password&lt;/label&gt;
                      &lt;input type="password" ng-model="user.password" /&gt;
                  &lt;/div&gt;
                  &lt;div class="modal-footer"&gt;
                      &lt;button class="btn btn-warning" ng-click="cancel()"&gt;Cancel&lt;/button&gt;
                      &lt;input type="submit" class="btn primary-btn" value="Submit" /&gt;
                  &lt;/div&gt;
              &lt;/form&gt;
          &lt;/script&gt;
  </code></pre>
  
  <p></p>
  
  <p>I'm having a hard time figuring out how to attach the script to the actual submit button.  I added an id to  but the JS is looking for the form name (I know it's not myForm), which doesn't appear to be defined anywhere.  Feel like this should be easy but I'm missing something.</p>