This is a pretty old blog post about language-specific forms for EPiServer 7, but I still get quite a lot of traffic to it so I’ll keep it alive. There might be better ways to do this nowadays.
EPiServer and different kind of forms has always been somewhat a love vs. hate relationship for me. In earlier versions of EPiServer (4-6), it was really horrible to work with. I think all EPiServer developers can agree on that.
When EPiServer 7 came out it got a little bit better. But it was still very rough around the edges, to say the least. One thing I quickly noticed was that when you ran a multi-language website the form you created got confused about which language the user was visiting. So I created these extension methods to fix language-specific forms for EPiServer.
When working with Asp.Net MVC it’s pretty common to use an Html extension method called BeginForm. But if you’re using that method when working on an EPiServer 7 MVC site it’s important to remember that the method BeginForm isn’t language specific. That means if you’re having more than one language version of a specific page, the rendered form tag will use the URL of the default language of the page.
The solution for language-specific forms for EPiServer
Luckily the solution is simple, you just need to pass the current language code as a route value. One way of doing this is to simply add the value yourself everywhere you’re rendering a form,
This suggestion was found on EPiServer world forum.
Another way is to write some new extensions methods. I think this is a more convenient solution because you don’t have to remember to manually pass the language value every time. So these are the extension methods I came up with that covers all the way we’re rendering forms.
I named the extension methods to BeginFormWithCurrentLanguage to make it obvious what they are doing. And if you use these extension methods you’ll get language-specific forms for EPiServer, yay! 🙂
But as I wrote in the beginning of this blog post, this code was written for EPiServer 7 when it first came out. So use it at your own risk! 😉
Read more blog posts by me about EPiServer.