Return in a view-specific div

1

I have a view where the contact form is at the bottom of the page, with validation via DataAnnotations. When I click the send button, the controller checks the ModelState, if it is not valid, it returns to the view with the validation messages. Home However, it returns at the top of the page (view) and as the form of contact is at the bottom of the page, you would have to scroll to the contact to see the messages. In the case, I'm using the scrollspy of the bootstrap and I'd like to know if I have to return the view exactly in the contact div to return directly to the error messages.

    
asked by anonymous 02.06.2015 / 08:51

3 answers

0

Get the id of the div that has been validated the fields and put in this command:

$('html, body').animate({ scrollTop: $('#IdDiv').offset().top }, 'slow');
    
03.06.2015 / 19:25
0

If I understand how Scrollspy works, it scrolls by itself to a certain <div> when you click a button when the document is ready ( $(document).ready() ). Validation information is generated by Helper in Razor (% with%). So to get what you want, the following code should resolve:

<div class="div-do-scrollspy">
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    ...
</div>
    
02.06.2015 / 17:42
0

Well, I did it this way:

I passed a value through ViewBag as Cigano Morrison Mendez spoke, and in Javascript I used the method that Tiago Falcão mentioned. Now when the page loads I check if it has the value in the viewbag (which only receives qnd has the validation) and only then executes the function js

    
05.06.2015 / 01:27