0

I am new to MVC and am struggling to get my head round it coming from a web forms background.

I have two classes for a timesheet application, Week and TimeEntry:

public class Week
{
    public int WeekID { get; set; }
    public DateTime WeekStartDate { get; set; }
    public string UserID { get; set; }
    [ForeignKey("UserID")]
    public virtual ApplicationUser ApplicationUser { get; set; }
    public virtual ICollection<TimeEntry> TimeEntries { get; set; }
}

public class TimeEntry
{
    public int TimeEntryID { get; set; }
    public int ClientID { get; set; }
    [ForeignKey("ClientID")]
    public virtual Client Client { get; set; }
    public double MonHours { get; set; }
    public double TueHours { get; set; }
    public double WedHours { get; set; }
    public double ThuHours { get; set; }
    public double FriHours { get; set; }
}

I want to be able to create the TimeEntry objects "on the fly" from the Week controller.

The idea is to have a way of inputting the time like this: enter image description here

(I'm planning on using JQuery to create a new row when needed, but will try and figure this bit out later!)

Appreciate this is a noob question, but can't figure out what I need to be looking up on Google!

Community
  • 1
  • 1
Ben
  • 4,281
  • 8
  • 62
  • 103
  • you need to have your javascript create your elements in the way that the modelbinder can re-build the collection on submission back to the server. [Here's](http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/) an article on how to do it, and [here's](https://stackoverflow.com/questions/9915612/how-can-i-add-rows-to-a-collection-list-in-my-model) a similar post with helpful answers. – Jonesopolis Jun 15 '17 at 21:25
  • For a more complete example using `BeginCollectionItem`, refer [this answer](https://stackoverflow.com/questions/40539321/a-partial-view-passing-a-collection-using-the-html-begincollectionitem-helper/40541892#40541892) –  Jun 16 '17 at 01:03

0 Answers0