3

It works fine with the code below is I only have one parameter but how do I do TWO input parameters? If I just use [HttpGet] then none of the parameters are send though it works fine outside of Swagger. Help ?

//[HttpGet]
[Consumes("application/json")]
[HttpGet("{caseId}")]
public ActionResult Get(string caseId, string fileName)
{
    return null;
}
6
  • 1
    is this asp.net core? Commented Oct 21, 2016 at 17:20
  • why you don't use a ViewModel instead of those 2 parameters? Commented Oct 21, 2016 at 17:26
  • yes this is asp.net core Commented Oct 21, 2016 at 18:24
  • The resource can be identified using caseId and fileName together? Is that correct? Commented Oct 21, 2016 at 18:26
  • I'm not sure if I understood well your question. You want your get method to receive both parameteres, and show it in Swashbuckle? Commented Oct 21, 2016 at 18:29

2 Answers 2

3

Try using the FromUri or querystring attributes in your method signature

[Consumes("application/json")]
[HttpGet("{caseId}")]
public ActionResult Get(string caseId, [FromUri] string fileName)
{
    return null;
}

or

[Consumes("application/json")]
[HttpGet("{caseId}")]
public ActionResult Get(string caseId, [QueryString] string fileName)
{
    return null;
}

This should now document in swagger showing that the caseId is part of the route and that the fileName should be specified.

Sign up to request clarification or add additional context in comments.

1 Comment

Is the best practice to use a ViewModel for anything more than one input parameter
1

I was just experimenting with this.

I found the following code works with Swagger:

[HttpGet("{entityId}/{monthsOfHistory}")]
public async Task<ActionResult<DateTime>> GetAsync([FromRoute] int entityId, [FromRoute] int monthsOfHistory)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.