Set focus on on ASP.NET MVC model errors

后端 未结 2 562
太阳男子
太阳男子 2021-01-02 09:39

I\'ve got a model that does some validation checking and adds the errors to ModelState:

ViewData.ModelState.AddModelError(\"mycontrol\", \"message\")
         


        
2条回答
  •  我在风中等你
    2021-01-02 10:19

    You could use JavaScript to find the input elements on the page that have the MVC validation HTML class (input-validation-error) added, and move the carat to the first one. That /should/ move the screen to that element although I haven't tested it.

    A JS library such as jQuery will make this straightforward to do.

提交回复
热议问题