开发者

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

开发者 https://www.devze.com 2023-01-19 14:56 出处:网络
I have a select: <%: Html.DropDownListFor(c => c.DataTextField, Model, \"Please select\", new { id=\"selected-contract\"}) %>

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

精彩评论

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

关注公众号