In the following class
using System;
namespace Beverati.Repository.ViewModel
{
[Serializable]
public class CollectionItem : EditableEntityBase
{
public CollectionItem() {}
private int? _quantity;
private string _retailValue;
private string _currencyName;
public int? quantity
{
get { return this._quantity ?? NULL_INTEGER; }
set { this._quantity = value; }
}
public string retailValue
{
get { return this._retailValue ?? String.Empty; }
set { this._retailValue = value; }
}
public string currencyName
{
get { return this._currencyName ?? String.Empty; }
set { this._currencyName = value; }
}
}
}
returned in this controller action
public IEnumerable<Repository.ViewModel.CollectionItem> GetAll()
produces this JSON output with MVC2 the JSON output like this
{
quantity:2
retailValue: 50.00
currencyName: USD
}
However, when I installed MVC4 the JSON returned looks like this
{
_quantity:2
_retailValue: 50.00
_currencyName: USD
}
All the property names have an underscore prefix. Why is the underscore being used and what should be done to have the public property names returned in the JSON?
The [Serializable] attribute is what’s doing it – Assuming you don’t need it for another purpose – remove the attribute and all should be well.