-1

I'm using the dropdownlist html helper and would like to perform an ajax call to the server when the value changes. I have seen the jquery code dropdownlist.change...

The problem I have is that I have a series of dropdownlist's name dropdownlist_1, dropdownlist_2, ...

I would like to be able to specify the same jquery function for each of these dropdownlist's. I have not been able to find a way to specify the function name in the dropdownlist html helper.

Thanks, Henry

2 Answers 2

1

Instead of attempting to specify it in the HtmlHelper, add a class name to each of your dropdown lists:

<%=Html.DropDownList("ddlName", new {@class="ajaxDropDown"})%>

or

<select class="ajaxDropDown" id="ddlOne">
  <option>1</option>
  <option>2</option>
  <option>3</option>
</select>
<select class="ajaxDropDown" id="ddlTwo">
  <option>Red</option>
  <option>Orange</option>
  <option>Blue</option>
</select>

Then use the classname to hook up the event via jQuery:

$('.ajaxDropDown').change(function() {
  $.get('/test', function(data) {
    ...
  });
});
Sign up to request clarification or add additional context in comments.

Comments

0

try this:

<%=Html.DropDownList("TopItemsList", ViewData["ListData"], new { @onchange="javascript();" })%> 

you can call the function you want.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.