I have a scenario in which I have to add comma separated string values to List model object. I am attaching controller method in which comma separated values are received from jquery code(js file). Please help.
public void update_session(string accntname, string bu, string salesop, string isdormant)
{
Console.WriteLine(accntname);/* receive values like BSNL,TATA in this accnt name*/
List<GridModel> lgm = new List<GridModel>();
string[] values = accntname.Split(',');
string[] values1 = bu.Split(',');
string[] values2 = salesop.Split(',');
string[] values3= salesop.Split(',');
}
public class GridModel
{
public string accntname{get;set;}
public string BU{get;set;}
public int salesop { get; set; }
public bool isdormant { get; set; }
}
I need to add values as shown below to the List model object by making in a loop
lgm.add(new GridModel{accntname=accntname,BU=bu,salesop=salesop,isdormant=isdormant})
What about something like that?
for(int i = 0; i < values.Length; i++)
{
lgm.Add(new GridModel{accntname = values[i], BU = values1[i], ... };
}
Additionally, you should implement a Constructor for the GridModel, would make your life a bit easier.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.