0

I have read this link: How to develop an ASP.NET Web API to accept a complex object as parameter?

And implemented the code just fine. Now I want to convert the 'firstName' parameter to accept an IList<string> collection. I have modified the class like this:

public class MyApiParameters
{
    public IList<string> FirstName { get; set; }
    public string LastName { get; set; }
    public DateTime BirthDate { get; set; }
}

I was hoping that the accepted URL would look like this:

http://localhost:58256/api/articles?firstName=matthew,andrew,philip,david&LastName=smith&birthDate=12-12-2012

But the parameter is only interpreted as a list if I pass it like this:

http://localhost:58256/api/articles?firstName=matthew&firstName=andrew&firstName=philip&firstName=david&LastName=smith&birthDate=12-12-2012
1
  • Could you show me Action declaration? Commented May 30, 2014 at 16:51

1 Answer 1

1

Add [FromUri] attribute annotation before you parameter and pass the second way of passing values you have mentioned in your question.

public MyApiParameters GetTest([FromUri]MyApiParameters test)
{
    return test;
}
Sign up to request clarification or add additional context in comments.

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.