Jot Dhaliwal
Jot Dhaliwal

Reputation: 1500

Dropdown bind onchange method in Razor

I have the following dropdown. How can I bind the OnChange method to it?.

I am using Code first MVC approach. Also, how can I get the index value when binding on change method to it?

 <div class="editor-label">
     @Html.LabelFor(model => model.Id, "Empl")
 </div>
 <div class="editor-field">
     @Html.DropDownList("Id", String.Empty)
     @Html.ValidationMessageFor(model => model.Id)
 </div>

Upvotes: 0

Views: 2510

Answers (2)

jhayden
jhayden

Reputation: 1

@Html.DropDownList("Id", Enumerable.Empty<SelectListItem>(), new { onchange = "changeFunction()" })

That's assuming you want a blank list.

Upvotes: 0

Burak Karakuş
Burak Karakuş

Reputation: 1410

You can use JQuery to bind on change and then get the index then .

Something like this should take care of it..

Upvotes: 2

Related Questions