Azure function v3 - bind comma separated query string value to array/list in .net

Sanal Kumar Parakkad 151 Reputation points
2021-06-01T04:50:04.527+00:00

Hi,
I have a use case to bind query string to a model in Azure function V3 and in that, say, one of the query string will have array values. It is a .net core function app.

For eg: <url>?item=laptop&places=Bangalore&places=Chennai&places=Mumbai

This should be bound to a model like:

public class Items{

public string item { get; set; }
public List<string> places { get; set; }

}

Tried using FromQuery which doesn't seems to be supported in Azure function.

Could you please suggest?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,936 Reputation points Moderator
    2021-06-01T10:55:40.37+00:00

    @sanal-kumar-p-2758 Sharing previous discussion in stackoverflow. In the same thread there is another answer if you have predefine format and does not change.

    For your example you can use below code to get all places ?item=laptop&places=Bangalore&places=Chennai&places=Mumbai and similarly get other fields from query string and then bind it to your class.

     string[] places = req.Query["places"].ToArray();  
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.