我有这个模型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