Redirect form submit to anchor

I am using the code below to send the user to an anchor on submit of a form, but its not working. The page does refresh fine, but it doesn’t continue to the anchor #contact

using (Html.BeginForm("Index", "Home", new { ReturnUrl = "#contact" }, FormMethod.Post, new { novalidate = "novalidate" }))

When the page refreshes I end up with a url looking like this, which in honesty doesnt look right to me either

http://localhost:52438/?ReturnUrl=%23contact

or thought this maybe

using (Html.BeginForm("Index", "Home", FormMethod.Post, new { novalidate = "novalidate" } + "#contact"))

So i tried this and yes it hides the return URL bit, but it doesnt go to the anchor, I’m probably miles off in honesty

using (Html.BeginForm("Index", "Home", FormMethod.Post, new { novalidate = "novalidate" }))
 {
 @Html.Hidden("returnUrl", "#contact")

OK I’m still trying, I’m doing this now, but cant test it as there a squiggly line under ClientScript

using (Html.BeginForm("Index", "Home", FormMethod.Post, new { novalidate = "novalidate" }))
{
ClientScript.RegisterStartupScript(this.GetType(), "hash", "location.hash = '#contact';", true);

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.