1

I have html dropdown

@using (Html.BeginForm("SetCulture", "Home"))
{
    <fieldset>
        <select id="lngSelect" class="form-control">
            <option name="culture" id="en-us" value="en-us">Eng</option>
            <option name="culture" id="es" value="es">Es</option>
            <option name="culture" id="ar" value="ar">Ar</option>
        </select>
    </fieldset>
}

jquery script

<script type="text/javascript">
    (function ($) {
        $("#lngSelect").change(function () {
            $(this).parents("form").submit(); // post form
        });
    })(jQuery);

and controller action

public ActionResult SetCulture(string culture)
{
    ...
}

I need to pass value selected option to controller, but value passed is null instead of en-us, es, ar... I have tried to change name of controller parameter to "id" and "value", but still it's null in controller..

Can someone help me solve this?

2 Answers 2

2

name attribute should be on select itself and not on option:

<select name="culture" id="lngSelect" class="form-control">
  <option  id="en-us" value="en-us">Eng</option>
  <option  id="es" value="es">Es</option>
  <option  id="ar" value="ar">Ar</option>
</select>
Sign up to request clarification or add additional context in comments.

Comments

1

Your <select> does not have a name attribute so there is no name/value pair to submit. Change it to

<select id="lngSelect" name="culture" class="form-control">
    ....
</select>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.