How to put a form in the _Layout view?

1

I'm trying to make a website with two languages support.

First test I did was put this code inside a view common, the index of my control Home .

It worked perfectly.

When I put the same code in a partial view and call it in _layout view it does not work. Can anyone tell me what I'm doing wrong?

Below is the code as it is in partial view , which does not work is form submit.

@{
    var culture = System.Threading.Thread.CurrentThread.CurrentUICulture.Name.ToLowerInvariant();
}

@helper selected(string c, string culture)
{
if (c == culture)
{
        @:checked="checked"
        }
}

@using (Html.BeginForm("SetCulture", "Home"))
{
    <fieldset>
        <legend></legend>
        <div class="control-group">
            <div class="controls">
                <label for="en-us">
                    <input name="culture" id="en-us" value="en-us" type="radio" @selected("en-us", culture) /> English <img src="http://st.xptotube.com/img/180x135/l/blank.png"class="flag flag-us" alt="United States of America" />
                </label>
            </div>
        </div>
        <div class="control-group">
            <div class="controls">
                <label for="pt-br">
                    <input name="culture" id="pt-br" value="pt-br" type="radio" @selected("pt-br", culture) /> Portugues <img src="http://st.xptotube.com/img/180x135/l/blank.png"class="flag flag-br" alt="Brasil" />
                </label>
            </div>
        </div>

    </fieldset>
}



@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    <script type="text/javascript">
        (function ($) {
            $("input[type = 'radio']").click(function () {
                $(this).parents("form").submit(); // post form
            });

        })(jQuery);
    </script>
}

I'm calling it like this on _Layout:

@Html.Partial("_Language")
    
asked by anonymous 28.10.2015 / 18:19

1 answer

2

Partials does not support @section Scripts . The correct would be for this code to be in _Layout or some View , but it would have to be modified. Do not leave it in Partial .

My suggestion for _Layout :

    <script type="text/javascript">
        (function ($) {
            $("input[type='radio'][name='culture']").click(function () {
                $(this).parents("form").submit(); // post form
            });

        })(jQuery);
    </script>
    
28.10.2015 / 19:18