开发者

jquery "serialize" and "formSerialize" do not serialize options added to select element at client side

开发者 https://www.devze.com 2023-03-19 17:17 出处:网络
var d = $(\'form[name=aspnetForm]\').formSerialize(); $.ajax({ type: \"POST\", data: d }); I have a ListBox with multiple selection to which options are added at the client side dynamically. The Lis
var d = $('form[name=aspnetForm]').formSerialize();
$.ajax({
  type: "POST",
  data: d
});

I have a ListBox with multiple selection to which options are added at the client side dynamically. The ListBox:-

 <select size="4" name="sel" multiple="multiple" id="sel">

I开发者_开发知识库 get every element in the form except the ListBox.Items.Count is Zero.

How can I serialize the ListBox along with other fields even if none of the Options is selected(I want to serialize every option in this ListBox, so that every options added at client side are available at server side).


You have to write custom code to serialize all options - One of the way is to do create a simple js object with text & value for each list option and then convert this array to string uing JSON serialization. You can pass this JSON string to server via hidden field. On server side, you have JSON serializers (JavascriptSerializer, DataContractSerializer) that you can use to parse your options data.

0

精彩评论

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

关注公众号