German Ortiz German Ortiz - 10 months ago 52
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?


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();