1

I have created a WCF Service (Ajax-enabled).

With [Serializable] attribute decorated to my class, the output looks as below:

<_x003C_FirstName_x003E_k__BackingField>ABC</_x003C_FirstName_x003E_k__BackingField> <_x003C_HomePhone_x003E_k__BackingField>1234567890</_x003C_HomePhone_x003E_k__BackingField> <_x003C_LastName_x003E_k__BackingField>PQR</_x003C_LastName_x003E_k__BackingField> <_x003C_MailAddress2_x003E_k__BackingField/>

And by removing the [Serializable] attribute to my class, the output does not render any data as below:

<FirstName i:nil="true"/<HomePhone i:nil="true"/<LastName i:nil="true"/ <MailAddress1 i:nil="true"/

Prem
  • 109
  • 1
  • 9

1 Answers1

0

There are two options :

  1. Add DataContract and DataMember to your code with Serializable.
  2. Add the line below to WebApiConfig.cs.

config.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings();

Jiayao
  • 510
  • 3
  • 7
  • Thanks for your response. I have tried your first option, and it does not render any data. And I do not have a WebApiConfig.cs in my project. – Prem Oct 01 '21 at 16:00
  • Maybe you can refer to [this post](https://stackoverflow.com/questions/13022198/how-to-remove-k-backingfield-from-json-when-deserialize) to find some solution. – Jiayao Oct 06 '21 at 06:53