Tharindu Senanayake Tharindu Senanayake - 6 months ago 32
SQL Question

Passing multiple array values to a web api controller using a single model attribute

I have a $scope object as bellow

$scope.array=[{"ID":"1","ID":"2","ID":"3"}];


What I want to do is pass these values to the following SQL query

Select * from table where ID in("Here I need the above 3 values one after another")


How can I do this?

Answer

Create a class

public class myId {
  public int ID {set;get;}
}

pass it to web api

public void submitID(List<myId> ids){
  // do rest of the things
  var id = string.Join(",", ids.Select(x => x.ID).ToArray());
  var query="Select * from table where ID in('"+id+"')";

}