【发布时间】:2020-09-24 03:06:49
【问题描述】:
我有一个 api,我在这里发送多个参数。 网址如下。
http://localhost:7150/api/logLoginDetails/GetLogLoginDetails?userId=&userIp=192.168.2.1&startTime=22.9.2020 18:07:13&endTime=23.9.2020 18:07:13
但是当我切换到api时,只有userIp信息来了。 userId字段应该为null,但是我应该怎么做才能确保包含datetime的字段不为null。
在下面的方法中,只填写了userIp信息。
[RoutePrefix("api/logLoginDetails")]
public class LogLoginDetailsController : ApiBaseController
{
[HttpGet, Route ("GetLogLoginDetails")]
public HttpResponseMessage GetLogLoginDetails (int? userId = null, string userIp = null, DateTime? startTime = null, DateTime? endTime = null)
{
try
{
return CROk (logLoginDetailsService.GetLogLoginDetails (userId: userId, userIp: userIp, startTime: startTime, endTime: endTime));
}
catch (Exception e)
{
return CRException (e);
}
}
}
【问题讨论】:
-
你需要用
[FromQuery]属性修改你的参数 -
@Eldar 我的项目不是核心项目
-
您通过查询字符串传递参数并期望在操作参数中具有相同的映射,这些映射会自动映射。您需要从 HttpContext 的 QueryString 中读取它,或者您可以使用 FormQuery 属性。
标签: c# datetime asp.net-web-api