views:

24

answers:

2

I have a select:

<%: Html.DropDownListFor(c => c.DataTextField, Model, "Please select", new { id="selected-contract"}) %>

and on change I am calling an action via $.getJSON:

   $("#selected-contract").change(function () {

       $.getJSON("/Contract/List", [WHAT GOES HERE] ,updateList);

   });

The bit I am struggling with is passing back the ID of the item selected.

A: 

I was able to work this out:

$("#selected-contract").change(function () {
  $.getJSON("/Contract/List", { id: $("#selected-contract").val() }, updateList);
});

Thanks.

abarr
+1  A: 

What you have works, but you can shorten it a bit using this inside the handler, for example:

$("#selected-contract").change(function () {
  $.getJSON("/Contract/List", { id: $(this).val() }, updateList);
});

It just saves you selecting the element all over again :)

Nick Craver