P.Brian.Mackey
P.Brian.Mackey

Reputation: 44295

Postback onchange with selected option value

I want to postback and pass in a parameter onchange. I have

@Html.DropDownList("CategoryID", (System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>)@Model.PhaseNames, new { @onchange = "location.href='/Home/Index?phaseFilter=this.value;'" })

This nearly works. this.value is not replaced with the selected option value as I would expect. Also, is there a better way to create the URL in this case?

Upvotes: 0

Views: 816

Answers (2)

Display Name
Display Name

Reputation: 4732

This should work:

@Html.DropDownList("CategoryID", (IEnumerable<SelectListItem>)@Model.PhaseNames, new { @onchange = "location.href='/Home/Index?phaseFilter=' + this.value;" })

Upvotes: 2

M4N
M4N

Reputation: 96606

I guess you wanted to write the onchange part like this:

@onchange = "location.href='/Home/Index?phaseFilter=' + this.value;"

Upvotes: 1

Related Questions