I am writing an application for storing school course data and I need to save 2 related models in a single view in .Net MVC, however I can't get my head around how this should be put together.
I have 2 models, Subjects and Classes, one subject can have many classes. In my view I want to allow the user to enter details for a new subject and also assign classes to that subject in a single form submit.
Example:
Subject Name
Subject Lead Teacher Name
(the fields below may be recursive if there are many classes for a single subject)
Class Name
Class Start Time
Class Teacher Name
The user would come along and enter the subject name and subject lead teacher name, followed by enter a new class name, start time and class teacher name, once they have done this they would submit the form and I need to save Subject Name and Subject Lead Teacher Name to the Subjects model and Class Name, Class Start Time and Class Teacher Name to the Classes.
- How do I go about creating the form fields in a single view for 2 models?
- How do I take the submitted data and save it back to 2 separate models?
If anyone can help me with this and provide some sample code that would be awesome as I am lost at the moment!