当前我正在从angular发送一个看起来完全像这样的对象。
{"部门":2,"备注":"asdf","周末结束":"2019-11-02T00:00:00"}
然后我在我的.net控制器中点击这个方法,它看起来像这样。
[HttpPost]
[Route("Edit")]
public void Edit([FromForm] CorpNotes newMessage)
{
//_SLGContext.Entry(newMessage).State = EntityState.Modified;
//_SLGContext.SaveChanges();
}
这是我在下面的CorpNotes模型
public class CorpNotes
{
public string Department { get; set; }
public string Note { get; set; }
public string WeekEnding { get; set; }
}
我在Post方法Edit((中接收到变量CorpNotes newMessage中的所有空值
为什么我所有的值都为空?slg corp notes.service.ts
updateMessage(message: any) {
console.log("at service")
console.log(message)
var newMessage = new CorpNotes(message['departments'], message['noteBody'], message['weeks'].weekEnding)
var Params = '?Department=' + message['departments'] + '&Note=' + message['noteBody'] + '&WeekEnding=' + message['weeks'].weekEnding
console.log(newMessage)
console.log(JSON.stringify(newMessage))
console.log(Params)
const headers = new HttpHeaders()
.set('Content-Type', 'application/json;charset=UTF-8')
let options = { headers: headers };
return this.http.post(this.baseUrl + 'api/SlgCorpNotes/Edit', JSON.stringify(newMessage), options);
//return this.http.post(this.baseUrl + 'api/SlgCorpNotes/Edit', JSON.stringify(newMessage))
}
-
从Angular
http.post
调用中删除JSON.stringify
。它应该能够识别一个物体。 -
JSON中的最后一个字段是日期,但C#模型需要一个字符串,也可以将其更改为日期。