Set focus on on ASP.NET MVC model errors

后端 未结 2 544
太阳男子
太阳男子 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:01

    Some jquery goodness to scroll to the first input with an error. The tricky bit is that you have to get the underlying DOM element BEFORE you invoke focus() as the focus() method on a jQuery object fires the focus event instead of giving focus to the element.

    
    

提交回复
热议问题