German Ortiz German Ortiz -4 years ago 176
C# Question

change action name depending of dropdownlist value MVC

Is it possible to change the action name according to the dropdownlist value?

Here is the dropdownlist

@{Html.DropDownList("import", @ViewData["list"] as SelectList)}

And the form

@using (Html.BeginForm(dropdownlist.value(), "Files", FormMethod.Post, new { enctype = "multipart/form-data" }))

How can I do that?

Answer Source

You have to do it in the client side. try this.

  @{Html.DropDownList("import", @ViewData["list"] as SelectList)}

    <script type="text/javascript">

        $('select[name=import]').change(function () {
            document.formsame.action = "controllerName" + $(this).val();

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download