Url On Html.BeginRouteForm Not Correct

I’ve had this issue on Sitecore 6.6 but someone recently had a similar issue on Slack in a recent version of Sitecore and my keyboard bashing solution fixed it for them as well. So I’ll put it up here. At some point I’d like to dig in to the code for Html.BeginRouteForm in a bit more detail so I can work out why it’s not working as expected.

Anyway – you have a form with this code:

@using (Html.BeginRouteForm(Sitecore.Mvc.Configuration.MvcSettings.SitecoreRouteName, FormMethod.Post))

However the Url it posts to is not the same as the Url you’re currently on. This caused us issues because there was some redirect stuff for SEO and it was triggering and then redirecting away from the POST and getting all in a muddle.

If you use this instead:

@using (Html.BeginForm())

It just uses the current Url and everything works fine.

I implemented this fix at the 11th hour without being able to research (a) why it was a problem and (b) the ramifications of using BeginForm instead. It works though. Shrugs

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s