I have this model with System.Runtime.Serialization attributes:
[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; }
}
And after that in Razor Model.DataTablesDescription (this is List<DataTableItemModel>
):
@Html.Raw(new JavaScriptSerializer().Serialize(Model.DataTablesDescription))
or
@Html.Raw(Json.Encode(Model.DataTablesDescription))
Output HTML looks as:
[{"Targets":[0],"Visible":false,"Searchable":false,"Field":"Id"}, ...]
but I expected:
[{"targets":[0],"visible":false,"searchable":false,"name":"Id"},
i.e. subject to DataMember attributes.
What's wrong?