I'm having a very weird case in my querystring for [FromUri]. The code below is my model parameter
public class PagingParams
{
public PagingParams()
{
// set the default values
this.PageNo = 1;
this.PageSize = 30;
}
public int PageNo { get; set; }
public int PageSize { get; set; }
public string OrderBy { get; set; }
}
This is my controller code.
[Route("search")]
[ResponseType(typeof(PagingList<EmailTemplatesInfo>))]
public async Task<IHttpActionResult> Search(SearchParams searchOption, [FromUri] PagingParams p)
{
// Check
if (searchOption == null) return BadRequest("Invalid search options");
// Filter EmailTemplate by Keyword
var emailTemplate = db.EmailTemplates.Where(et => et.Name.Contains(searchOption.Keyword) ||
et.Description.Contains(searchOption.Keyword)).ProjectTo<EmailTemplatesInfo>();
// Filter by Status
emailTemplate = emailTemplate.Where(et => searchOption.Status.Contains(et.Status));
// Check & Set
if (p == null) p = new PagingParams();
// Set Default Sort
if (string.IsNullOrEmpty(p.OrderBy)) p.OrderBy = DEFAULT_ORDERBY;
return Ok(new PagingList<EmailTemplatesInfo>(p, emailTemplate));
}
Base on the code above if i want to pass in Parameter Binding for PagingParam.
Should be this url
- search?PageNo=1&PageSize=10&OrderBy=CreatedOn
But the result i get in swashbuckle it become
- search?p.PageNo=1&p.PageSize=10&p.OrderBy=CreatedOn
the object name for PagingParam need to append in the querystring