Handle user hitting 'Enter' key in a ASP.NET MVC web site

后端 未结 6 2104
星月不相逢
星月不相逢 2020-12-29 03:32

I am working on a ASP.NET MVC web site that has multiple submit buttons. i.e.

    
    &         


        
6条回答
  •  [愿得一人]
    2020-12-29 04:13

    You should only have one submit button. The reset button should be type="reset" and the back button should probably be type="button" like this:

    
    
    
    

    Then, Reset and OK will just work the way they are supposed to and you'll only need to handle the Back button click with Javascript.

    Edit: The other option would be to place the Reset and Back submit buttons each in their own forms inside iframes. Then they would be ignored by the main form and wouldn't be default buttons. Also, this would allow you to point them to different server actions if needed and there wouldn't be any reliance on Javascript for the button actions.

提交回复
热议问题