我在HttpGet动词中将空参数值传递给模型的属性时遇到问题。
我将.Net Core 2.1用于我的Web API项目。下面是我在控制器中的操作方法:
[HttpGet("get")]
public ActionResult GetData([FromQuery]MyTestModel model)
{
var result = new MyTestModel();
return new JsonResult(result);
}
Run Code Online (Sandbox Code Playgroud)
我的MyTestModel.cs就像:
[Serializable]
public class MyTestModel
{
public MyTestModel()
{
PageNo = 1;
PageSize = 10;
}
public int ClientId { get; set; }
public int? CandidateId { get; set; }
public DateTime? FromDate { get; set; }
public DateTime? ToDate { get; set; }
public int PageNo { get; set; }
public int PageSize { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
当我像这样调用API时: …
model-binding asp.net-core-mvc .net-core asp.net-core-webapi