我有這個模型System.Runtime.Serialization屬性:數據成員屬性不是JSON影響導致
[DataContract]
public class DataTableItemModel
{
[DataMember(Name = "targets")]
public int[] Targets { get; set; }
[DataMember(Name = "visible")]
public bool Visible { get; set; }
[DataMember(Name = "searchable")]
public bool Searchable { get; set; }
[DataMember(Name = "name")]
public string Field { get; set; }
}
而在這之後的剃刀Model.DataTablesDescription(這是List<DataTableItemModel>
):
@Html.Raw(new JavaScriptSerializer().Serialize(Model.DataTablesDescription))
或
@Html.Raw(Json.Encode(Model.DataTablesDescription))
輸出HTML看起來:
[{"Targets":[0],"Visible":false,"Searchable":false,"Field":"Id"}, ...]
,但我預計:
[{"targets":[0],"visible":false,"searchable":false,"name":"Id"},
即受到數據成員屬性。
怎麼了?
可能有助於http://stackoverflow.com/questions/6020889/asp-net-mvc-3-controller-json-method-serialization-doesnt-look-at-datamember-n – Satpal 2015-04-02 10:13:19