1
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; }
}
}
}
返回在本控制器操作
public IEnumerable<Repository.ViewModel.CollectionItem> GetAll()
產生具有MVC2此JSON輸出的JSON輸出這樣
{
quantity:2
retailValue: 50.00
currencyName: USD
}
然而,當我安裝MVC4的JSON返回看起來像這樣
{
_quantity:2
_retailValue: 50.00
_currencyName: USD
}
所有屬性名稱都有一個下劃線前綴。爲什麼使用下劃線,以及如何讓JSON中返回公共屬性名稱?
工作。有趣的是,因爲在MVC2中,我需要該屬性才能使序列化工作。你知道一個參考來解釋MVC4中的[Serialize]屬性的影響嗎? – ChrisP