Удалить дополнительный объект из списка С# <объект> вернуть ответ json из веб-формы asp.netC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Гость
 Удалить дополнительный объект из списка С# <объект> вернуть ответ json из веб-формы asp.net

Сообщение Гость »


I'm newbie in asp.net webform. I have so many problems that's almost I got solution from StackOverflow. But Now I'm facing an issue and can't get any desired solution, So, I'm writing this question. I want a textbox to autocomplete with JQuery autocomplete call. I have two textboxes, one is for autocomplete suggestion list, another is getting selected item Id. I don't know how modern website do this. But fortunately, I got a hints by googling it.

Here I have create a codebehind [WebMethod] attribute Method:

// Class for Custom datatype object public class MyData { public int Id { get; set; } public string Value { get; set; } } // Webmethod for call from ajax [WebMethod] public static MyData GetDataList() { int id = 123; string value = "My Name"; return new MyData { Id = id, Value = value }; } And here is my JQuery function.

$(function () { $("#autocomplete").autocomplete({ source: function (request, response) { $.ajax({ type: 'POST', url: 'reissue_ticket.aspx/GetDataList', data: '{ "term": "' + request.term + '" }', contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (data) { response(data.d); }, error: function () { console.log('Error fetching items.'); } }); }, minLength: 1, select: function (event, ui) { // Set the selected value and id into textboxes $('#selectedValue').val(ui.item.value); $('#selectedId').val(ui.item.id); } }); }); It's work fine but problem is I got 3 object response. like:

json respose text

{ "d": { "__type": "eLedger.com.Pages.Services.reissue_ticket+MyData", "Id": 123, "Value": "My Name" } } I don't want"__type": "eLedger.com.Pages.Services.reissue_ticket+MyData". I tryed in c# like Json Serialized but nothing works.

Please someone help me to get this problem solve or any better idea with webform.

Thanks in advance for reading my problem at least.

I want the response like {"Id":1, "Value": "My Name"} only.


Источник: https://stackoverflow.com/questions/780 ... om-asp-net
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»