I'm new to MVC, but have done a bunch of reading the past few months, and I've ran into some issues when trying to build a one to many relationship dynamically on the page. I've set up the logic and can accomplish this through multiple page loads but I want the form to be more dynamic, so I'm not sure what the correct way to do this is.
For testing purposes I scaled down my Model just to see if I can get the interaction I want before I apply it to my project and what I have is this:
Generated models from my Db.
public partial class TestIncident
{
public TestIncident()
{
this.TestGeoKits = new HashSet<TestGeoKit>();
}
public int RecordID { get; set; }
public string OwnerFirstName { get; set; }
public string OwnerMiddleName { get; set; }
public string OwnerLastName { get; set; }
public virtual ICollection<TestGeoKit> TestGeoKits { get; set; }
}
RecordID being my PKey for the class above
public partial class TestGeoKit
{
public int RecordID { get; set; }
public int KitID { get; set; }
public bool SubmittedForTestingFlag { get; set; }
public string SubmissionLocation{ get; set; }
public Nullable<System.DateTime> SubmissionDate { get; set; }
public bool Processed { get; set; }
public Nullable<System.DateTime> ReturnDate { get; set; }
public string Notes { get; set; }
public virtual TestIncident TestIncident { get; set; }
}
RecordID being my FKey relation and KitID being my PKey for this table.
Now, I need to set up a Create View that contains both the Form associated with the TestIncident AND has the option to click an ADD button to populate Partials containing the Form associated with my TestGeoKits on the same page, instead of after a postback and redirect (How I currently have it). I've tried piecing information from multiple posts together to accomplish this, but one way or another I run into a bunch of problems and even more questions..
Logically I would think, being MVC uses Entity Framework, that on my Create TestIncident page I can have an ADD button that adds a TestGeoKit form to the page each time its clicked, in the form of a partial view. Then, when you click submit the entire Object is passed back to the Controller, binds all the values for the incident to the database, gets the next Identity Value (set up in sql) for RecordID, and uses that information for the ICollection of TestGeoKits in TestIncident to build the foreign key relationship and save all the data.
How do I go about building a dynamic page like this? I've read MANY articles, played with Ajax commands and jQuery form controls, played with LazyLoading / EagerLoading, and I think I'm over complicating it for myself at this point.
I have a, not so dynamic, version currently running that when you submit your TestIncident form, the Method called in the Controller checks for a GeoKitCollectedFlag after its saved and if its true redirects you to a separate page to fill out the GeoKit Form. But, again my ideal form is to combine these two actions on one page.
Any help would be greatly appreciated!