Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to render Nested ViewModels, collections #44

Closed
weedkiller opened this issue Feb 22, 2017 · 3 comments
Closed

How to render Nested ViewModels, collections #44

weedkiller opened this issue Feb 22, 2017 · 3 comments

Comments

@weedkiller
Copy link

weedkiller commented Feb 22, 2017

hi I saw the one sample on collections, fro ASP MVC 5

walking down the collection StudentWeekVM but I was not able to get it to work with 2 nesting levels - can you please show me how I would wire this up? and on submit does it submit the entire StudentWeekVM collection it contains

For ex. show the Student Week Schedule with student Hours,

  • showing days on top <monday, tuesday, >

  • and classes on the side like this image

       // the over all container/collection of `ClassTimeGroup`
      public class StudentWeekVM
      {
          public StudentWeekVM()
          {
              Records = new List<ClassTimeGroupVM>();
              Totals = new List<LabHoursEnteryVM>();
              for (int i = 0; i < 7; i++)
              {
                  Totals.Add(new LabHoursEnteryVM());
              }
          }
          [DisplayFormat(DataFormatString = "{0:dddd d MMMM yyyy}")]
          public DateTime WeekEnding { get; set; }
          public StudentVM Student { get; set; }
          public List<ClassTimeGroupVM> Records { get; set; }
          public List<LabHoursEnteryVM> Totals { get; set; }            
          public decimal GrandTotal { get; set; }
          public int SelectedProject { get; set; }
          public int SelectedClassDayOrNight { get; set; }
          public IEnumerable<SelectListItem> Projects { get; set; }
          public IEnumerable<SelectListItem> ClassDayOrNights { get; set; }
      }
    
    // a row of the class with the weekly hours <monday, tues etc>
      public class ClassTimeGroupVM
      {
          public ClassTimeGroupVM()
          {
              TimeRecords = new List<LabHoursEnteryVM>();
              Total = new LabHoursEnteryVM();
              for (int i = 0; i < 7; i++)
              {
                  TimeRecords.Add(new LabHoursEnteryVM());
              }
          }
          public ClassDayOrNightVM ClassDayOrNight { get; set; }
          public List<LabHoursEnteryVM> TimeRecords { get; set; }
          public LabHoursEnteryVM Total { get; set; }
      }
      public class ClassDayOrNightVM
      {
          public int ID { get; set; }
          public string Name { get; set; }
          public ClassesVM Project { get; set; }
      }
      public class LabHoursEnteryVM
      {
          public int? ID { get; set; }            
          public decimal Hours { get; set; }
      }
    
@mcintyre321
Copy link
Owner

mcintyre321 commented Feb 22, 2017 via email

@reiphil
Copy link
Contributor

reiphil commented Jun 11, 2018

@mcintyre321 - hey, just wondering if there has been any movement on nested collections or how we should interact/use them.

@mcintyre321
Copy link
Owner

The PR with nested collections can't be accepted in it's current state. If someone is able to extract the code from that PR for making the nested collections work and send a PR I will happily accept.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants