【发布时间】:2018-09-25 07:32:17
【问题描述】:
我创建了基于 .Net-Core 的 Web.Api。有两种方法:
- IEnumerable GetRoles() - (Get)
- ResponseObject GetUsers(PagerRequest pagerRequest) -(发布)。它具有以下属性: [Route("api/users/getusers")] [HttpPost]
这两种方法都由 Angular 调用。方法 GetRoles 正在查找,但问题出在 POST 中。
PagerRequest 是一个简单的类,它有一些 int 属性。它由 Angular 填充。 Fiddler 显示正确的 JSON:
POST http://localhost/Pir.API/api/users/getusers HTTP/1.1
Host: localhost
Connection: keep-alive
Content-Length: 84
Accept: application/json, text/plain, */*
Origin: http://localhost:4200
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
content-type: application/json
Referer: http://localhost:4200/
Accept-Encoding: gzip, deflate, br
Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7
{
"CountButtons": 5,
"ItemsCount": 0,
"PageSize": 5,
"CurrentPageIndex": 0
}
GetUsers 方法正在调用,但输入参数未初始化。换句话说,反序列化不起作用,我不明白为什么。
之前这个项目是基于经典的 .Net 并在 IIS 中运行的。它工作正常。但是.Net CORE 是个问题。
谁知道问题出在哪里?
以下代码示例:
------------- PagerRequest.cs --------
public class PagerRequest
{
public int ItemsCount { get; set; }
public int PageSize { get; set; }
public int CurrentPageIndex { get; set; }
public int CountButtons { get; set; }
}
------------- PagerRequest.ts --------
export class PagerRequest{
ItemsCount:number;
PageSize:number;
CurrentPageIndex:number;
CountButtons:number;
}
【问题讨论】:
标签: c# angular asp.net-core .net-core