I have created a contact form. In this contact form the user can enter data such as first name, last name, telephone number and so on. After the user submits the form I execute a server-side validation. I would like to redirect the user back to the same view if the validation was successful and unsuccessful. This works without problems. But the scroll position of the view is at the top again. But the form is at the very bottom. The user should get the form displayed again directly. So in other words: I want to return the same view to the user but keep the scroll position. How do I achieve this in ASP.NET MVC 5?
My server-side code looks like this:
public ActionResult Contact(ServiceModel model)
{
if (ModelState.IsValid)
{
ViewBag.SuccessMessage = " succeeded";
return View("Index");
}
else
{
if (!this.IsCaptchaValid(""))
{
ViewBag.ErrorMessage = "Error. Try again.";
}
return View("Index", model);
}
}
Thank you.