1

enter image description hereI 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?

Dragon
  • 1,078
  • 2
  • 9
  • 31
  • We need to see the code, not a drawing of the form. – Ant P Oct 18 '14 at 21:11
  • Seems you kinda misunderstood MVC pattern... And, please, check your formatting, so other people won't have to clean it after you. – walther Oct 18 '14 at 21:33
  • You should reconsider your database design. If you have 3 fixed subjects then have a field for each. If you have variable number of subjects you should have 2 tables, one of students and one for subjects with a FK relationship to the studentID. –  Oct 18 '14 at 23:10
  • no actually the subjects are variable and they are generated at runtime so a fk cannot be used here. – Dragon Oct 19 '14 at 08:46

1 Answers1

1

You will need to bind values to a view model, i.e., 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; }
}
beautifulcoder
  • 10,832
  • 3
  • 19
  • 29