ASP.NET Core WebAPI无法检测从Angular 2

时间:2017-05-18 04:29:07

标签: angular viewmodel asp.net-core-1.0 icollection

我正在开发Angular 2,并尝试将嵌套对象发布到ASP.NET MVC Core 1.1 WebAPI。

前端可以使用以下样本数据发布为“multipart / form-data”:

------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="title"

ABC Project 2
------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="description"

dsfsdfdsfdsf
------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="category"

null
------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="projectType"

Campus Rejuvenation
------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="status"

Proposed
------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="supportedBy"

SC2 - Teaching & Learning Facilities
------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="startDate"

1899-12-23
------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="endDate"

9999-12-31
------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="latitude"

0
------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="longitude"

0
------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="building"

null
------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="cost"

21313123
------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="File"

undefined
------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="building"

Block C
------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="building"

Block C
------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="building"

Block C
------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="building"

Block D
------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="building"

Block B
------WebKitFormBoundarykzD6jBAQyRzMh9HI
Content-Disposition: form-data; name="sites"

[object Object]
------WebKitFormBoundarykzD6jBAQyRzMh9HI--

ASP.NET Core MVC 1.1无法检测从Angular 2发布的ViewModel的Site对象的问题。

示例JSON对象结构:

 {  
      "id":6156,
      "title":"45435345",
      "description":"trrtertertert",
      "category":"null",
      "projectType":"Smart Campus",
      "status":"Proposed",
      "supportedBy":"SC2 - Teaching & Learning Facilities",
      "startDate":"1899-12-30T00:00:00",
      "endDate":"9999-12-31T00:00:00",
      "latitude":0.0,
      "longitude":0.0,
      "building":null,
      "cost":232323.00,
      "files":[  
         {  
            "fileid":143,
            "fileName":"SampleFile.pdf",
            "createdTimestamp":"2017-05-16T06:05:47.7181311",
            "updatedTimestamp":"2017-05-16T06:05:47.9439996",
            "contentType":"application/pdf",
            "fileGuid":"d592cacc906c49faad3d6dff9571bf74"
         }
      ],
      "sites":[  
         {  
            "id":193,
            "building":"Block D",
            "latitude":1.3807812542822551,
            "longitude":103.84891247746054
         },
         {  
            "id":194,
            "building":"Block Q",
            "latitude":1.3806096427446133,
            "longitude":103.84793615337912
         },
         {  
            "id":195,
            "building":"Block N1",
            "latitude":1.3806096427446133,
            "longitude":103.85019993778769
         }
      ]
   }

项目的ViewModel:

public class ProjectViewModel
{
    public ProjectViewModel()
    {

    }

    public int id { get; set; }
    public string title { get; set; }
    public string description { get; set; }
    public string category { get; set; }
    public string projectType { get; set; }
    public string status { get; set; }
    public string supportedBy { get; set; }
    public DateTime startDate { get; set; }
    public DateTime endDate { get; set; }
    public ICollection<double> latitude { get; set; }
    public ICollection<double> longitude { get; set; }
    public ICollection<string> building { get; set; }
    public decimal cost { get; set; }
    public IFormFileCollection File { get; set; }
    public ICollection<sites> { get; set; }
}

0 个答案:

没有答案