I have a data in following pattern; as shown in image attached,
I want to repopulate all these values and controls on Postback. I am using asp.net MVC
If i should use a list then how can i tackle the multiple values of subject to be saved in one column but on view displayed in different column
currently using forms collection:
int rows=request.Form["rows"];
int colmn=requst.form["comn"];
var list1=new list<mymodel>{
new mymodel {}}
;
for (var row = 1; row <= noOfRows; row++)
{
list1.Add(new mymodel()
{
name= Request.Form["name-row"].ConvertToInt()
rollno= Request.Form["rollno-row"].ToString(),
});
for (int colmn = 1; colmn <= noOfColmns - 1; colmn++)
{
list1.Add(new mymodel()
{
subject = Request.Form["subj-row-colmn"].ConvertToInt()
});
}
}
let me know if something else is needed
Important Note:
I think i am not able to explain what i want,so i have narrowed a problem , To be more precise i have created a list ,i have populated a list as
var list1=new list<mymodel>{
new mymodel {}}
list1.Add(new mymodel()
{
name= Request.Form["name-row"].ConvertToInt(),
rollno= Request.Form["rollno-row"].ToString(),
subj=new list{}
});
,now i want to loop through this list to get all my values back in the given format. Q:how to get values from this list using loop(foreach or for) in the desired format?
You will need to bind values to a view model, ie, List<MyVM> vm
on postback. Then, each view model needs to keep a state for the CRUD. It can be a simple key / value pair, like:
public class MyVM
{
#region Properties
#endregion
public Dictionary<string, VMState> States;
}
public class VMState
{
public bool Create { get; set; }
public bool Read { get; set; }
public bool Update { get; set; }
public bool Delete { get; set; }
}
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.