0

I current have two models that are independent from each other but want to combine them in one view based on the month they were created.

 class Distance{
     public int Id{get;set;}
     public float DistanceRan { get; set;}
     public DateTime DateTime {get;  set;}
 }

and

 class Weight{
     public int Id{get;set;}
     public float CurrentWeight{ get; set;}
     public DateTime DateTime {get;  set;}
 }

I want to be able to create a view with the dates of the month: 1-12, that when clicked on would then take you to a page that would have each record of Weight/Distance that corresponds to that month.

I would assume I create a model such as:

 class WeightDistance{
     public int Id{get;set;}
     public List<Distance> Distance{ get; set;}
     public List<Weight> Weight{get;  set;}
 }

The logic behind getting each month isn't an issue, the problem is combining them both into a view. How would I go about creating a way to display these together? Would I create myself a controller to pull the data?

I have created a project before that had an Announcement Model and Comment Model, where it had a ModelView that would display all the comments in the details section of the announcement but the link was:

/Announcement/3/Details

Whereas this monthly view I want it to be:

/Month/2/...

Does that require a controller? Sorry I'm quite new and am finding it hard to find specific resources.

garfbradaz
  • 3,424
  • 7
  • 43
  • 70
Jane Doe
  • 21
  • 3

1 Answers1

0

Upload data into each model, then

class WeightDistance{
         public int Id{get;set;}
         public List<Distance> Distance{ get; set;}
         public List<Weight> Weight{get;  set;}
     }

Create View with that model. Then Create two partial views for 'Distance' and 'Weight' list. And then call those two partials form Parent view:

@Html.Partial("NameOfPartial",Distance)
@Html.Partial("NameOfPartial",Weight)

If you want to use two lists with mixed HTML, just create partials for single objects and iterate throw the lists calling the partials

foreach(var item in Distance)
{
  @Html.Partial("NameOfPartialForSingleObject",item)
}
foreach(var item in Weight)
{
  @Html.Partial("NameOfPartialForSingleObject",item)
}

Would I create myself a controller to pull the data? Yes, of course. But only parent view would need controller logic

Ssheverdin
  • 111
  • 5