【问题标题】:How to Pass Array Model as a value?如何将数组模型作为值传递?
【发布时间】:2018-03-29 13:52:25
【问题描述】:

我有一个名为 APIEntity 的模型类名称。并且有 DataObject[]。DataObject 有 10 个成员现在我想将成员作为值传递。我该怎么做?

这是我的模型:

public class APIEntity
{
    public List<int> unitCodes { get; set; }
    public DateTime start { get; set; }

    public DateTime end { get; set; }
    public DataObject[] fields { get; set; }
}

public class DataObject
{
    public string unitCode { get; set; }
    public string timedate { get; set; }
    public string latitude { get; set; }
    public string longitude { get; set; }
    public string ignition { get; set; }
    public string velocity { get; set; }
    public string positionerror { get; set; }
    public string digitherm5 { get; set; }
    public string direction { get; set; }
    public string distance { get; set; }
}

我只是想传递值:

var dat = new APIEntity()
{
    unitCodes = new List<int>() { 19215 },
    start = DateTime.ParseExact("2018-03-12 10:00:00", "yyyy-MM-dd HH:mm:ss", null),
    end = DateTime.ParseExact("2018-03-12 11:00:00", "yyyy-MM-dd HH:mm:ss", null),
    fields = ?????? // I want to pass the members here...unitcode,timedate,bla bla....
};

【问题讨论】:

  • fields属性的数据类型应该是什么?

标签: c# asp.net .net asp.net-mvc model


【解决方案1】:

试试这个:

var dat = new APIEntity()
{
    unitCodes = new List<int>() { 19215 },
    start = DateTime.ParseExact("2018-03-12 10:00:00", "yyyy-MM-dd HH:mm:ss", null),
    end = DateTime.ParseExact("2018-03-12 11:00:00", "yyyy-MM-dd HH:mm:ss", null),
    fields = new DataObject[] 
    {
        new DataObject { unitCode = "unitCode", timedate  = "timedate " }, 
        new DataObject { unitCode = "unitCode", timedate  = "timedate " }
    }
};

【讨论】:

    猜你喜欢
    • 2010-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-27
    • 1970-01-01
    • 2016-11-05
    • 2013-03-24
    • 2016-11-13
    相关资源
    最近更新 更多