I’ve got a page with some server side validation. It works, in that on a server validation failure it displays the same page, with a box with the validation errors above the form where the data was input.
My problem is that there is a whole bunch of other stuff at the top of the page, so the user isn’t directed to the error box, in fact it could be off screen. The errors are in a div #server_errors. What I want is to tell the controller to return the view, but jump to the errors section, the same as appending #server_errors to the url.
the controller returns like this:
public ActionResult ChangeRiskCategory(Guid id)
{
//...
//call server side method, handle errors
//...
return View("ChangeRiskCategory", changeRiskCategoryModel);
}
and I can’t see a way to inject the div id into the view at this point. I can see validating client side would solve this problem but it needs to work without js enabled so I think that rules that out.
You could try something like this:
(The “error” parameter is to stop it endlessly redirecting)
If you change your mind about using javascript you could simply emit: