开发者

Pass the id via getJson of the item selected in a select

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.


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 :)


I was able to work this out:

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

Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜