MVC Html.BeginForm and multiple languages


So how does Html.BeginForm build the action url for the form element.

It uses the UrlHelper class. My guess is that it will somehow try to identify the url for a specific controller/action + routevalues using the routetable. But i am pretty sure that it does not take langauge under consideration when doing this (hint: it does not). 

Well we did have problems with this, meaning submitting a simple form in a multi language episerver 7 mvc site.

We can solve it by manually creating the form element and getting the url for the page using and adding the actionname to it.

But do anyone have alternative solution for this challenge?

I did try to make my own .BeginForm() extension for this, but of course some of the methods involved is marked as private and internal in the System.Web.Mvc assembly, so i gave up (not worth the effort imho)

Aug 15, 2013 16:10

I think you can use html.translate for multiple languages. And just put xpath in language xml files.

Aug 16, 2013 3:16

Ok i think you missed the point. It has nothing to do with localization/translation.

Html.BeginForm writes out the form elements in html to be able to post something back to an action inside some controller. Typically you will post to an action in the same controller (not always i know)

On the form in the html you usally specifiy which url to post the result to, and usally Html.BeginForm will take care of this when you specify actionname and controllername. But the problem here is that we have multiple languages (read: urls) pointing to the same action/controller in the RouteTable.

So my form is being submitted to the wrong language of the page, because Html.BeginForm picks up the wrong language url.

Aug 16, 2013 9:21

Have you setted different languages in your form action url?

Do you just use just like the following?

@using (Html.BeginForm()) {

     <div >
             <div class="editor-label">
                 @Html.LabelFor(m => m.Account)
             <div class="editor-field">
                 @Html.TextBoxFor(m => m.Account)
                 @Html.ValidationMessageFor(m => m.Account)
            <div class="editor-label">
                 @Html.LabelFor(m => m.Password)
             <div class="editor-field">
                 @Html.PasswordFor(m => m.Password)
                 @Html.ValidationMessageFor(m => m.Password)
                 <input type="submit" value="submit"  />
Edited, Aug 16, 2013 9:29

I think you can use it like this:

@using (Html.BeginForm(new { Action = Model.ActionUrl }))
    // Your form...

Aug 16, 2013 9:31

Yeah we could do it like that, but it is just as bad as creating the form element manually and specifying the url.

What would be nice is an EPiServer html helper extension that could take the current language into consideration, but i am guessing i am asking for too much :)

One day when I have oceans of time i will make it (read: never)

Aug 16, 2013 10:13

My colleague just found the solution when he was looking at linking to other language branches using Html.PageLink.

Adding langauge routevalue did the trick:

@using (Html.BeginForm("SubMitting", "Test", new {language= ContentLanguage.PreferredCulture.Name}))


Aug 16, 2013 10:54

Cool man, thanks for sharing

Aug 16, 2013 11:17
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.