My WebAPI receives two strings, one containing the display values (names), one containing the hidden values (emails).
Before, it only received one string, over which it used a foreach, and I am unsure how to get it to work with two, how to fill "name" from "nameslist":
[System.Web.Http.HttpGet]
public AjaxAnswer BatchUserCreate(string email, string names) {
string[] emaillist = email.Split('\n');
string[] nameslist = names.Split('\n');
foreach(string email in emaillist) {
db.AddParameter("@email",email);
db.AddParameter("@name",name);
int newId = db.ExecuteScalar(userInsQuery);
}
return new AjaxAnswer(newId);
}
Zip the two lists together
var nameEmailPairs = emaillist.Zip(namelist, (email,name)=>new{email,name});
You can then foreach over that, which will have items with a name and an email.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With