[FromUri]模型默认参数

尝试如下方式, 默认参数均无.

/// <summary>
/// 总页数
/// </summary>
[DataMember(Name = "PageCount")]
[property: DefaultValue(0)]
public int PageCount { get; set; }
/// <summary>
/// 总记录数
/// </summary>
public int TotalItemCount { get; set; }
/// <summary>
/// 当前页数 (默认1)
/// </summary>
[DefaultValue(1)]
public int PageNumber { get; set; } = 1;

 public PageInfo()
{
     PageNumber = 1;
     PageSize = 20;
 }

最终想到在Controller方法中判断模型对象是否为空, 如果是空则new对象

[HttpGet]
[Route("list")]
public object list([FromUri(Name = "")] PageInfo pageInfo)
{
    if (pageInfo == null)
        pageInfo = new PageInfo();

    return ListSuccess(list, salesGoalListReceive);
}

留下评论