Page redirection when changing value in dropdown list

I have the following code that creates a drop down list.
When the user selects an item, I want to call a specific action in the controller and pass the new value as a parameter.

I have the following code, but this does not work, and I get "Invalid C regular expression" when I test Firebug.

@Html.DropDownList( "ctrlName", items, null, new { onchange = "document.location.href = /Controller/Action/this.options[this.selectedIndex].value;" }) 
+4
source share
2 answers

You are missing quotes in js

 @Html.DropDownList( "ctrlName", items, null, new { onchange = "document.location.href = '/Controller/Action/' + this.options[this.selectedIndex].value;" }) 
+5
source
 <%:Html.DropDownList("ctrlName", new[]{ new SelectListItem { Text="--Select--", Value="" }, new SelectListItem { Text = "KodefuGuru", Value = "Create" }, new SelectListItem { Text = "PlatinumBay", Value = "PlatinumBay" } }, null, new { onchange = "document.location.href = '/Controller/Action/'+this.options[this.selectedIndex].value;)" })%> 
+1
source

All Articles