0

Im my project I have a class called Clubs and each club has a list of members which are apart of a different class called ClubMembers. I am wondering how I would create a edit view that would allow me to add and remove members to that list.

This is my Club Model:

 public class Club
    {
        // Class to manage a single Club
        [Key]
        public int ClubID { get; set; }


        //List of Members that are members of this Club
        public virtual List<ClubMember> ClubMembers { get; set; }   


    }//end Club

This is my ClubMembers model:

 public class ClubMember
    {
        [Key]
        public int UserId { get; set; }


        //Foreign Key for Club
        public int ClubID { get; set; }

        [ForeignKey("ClubID")]
        public virtual Club Club { get; set; }
    }//end User Class

To summarize what I would like is to be able to have an edit view that allows me to add and remove members and also change the details of the club.

Would this be possible on the same view as they are of different models?

If you would like to look at anymore of my code please ask.

Cathal O 'Donnell
  • 495
  • 3
  • 9
  • 32
  • Refer the answers [here](http://stackoverflow.com/questions/29161481/post-a-form-array-without-successful/29161796#29161796) and [here](http://stackoverflow.com/questions/28019793/submit-same-partial-view-called-multiple-times-data-to-controller/28081308#28081308) for some options –  Feb 11 '16 at 12:46

2 Answers2

0

First late me clear, are you going to implement one to many relation ship..? It means one Club having many Members..? If yes then you may have two different approach.

  1. You implement both on same page
  2. Or, you may create two different pages

Best practice says that create one Master of Club with CRUD operation and then refer use this master as Dropdown during creating Club Members.

Vikas
  • 39
  • 11
0

You could create a view model with all the properties you want in your view, which you have strongly typed to that view model. Use the controller to create a new instance of that view model and return it to the view using the GET-action method. Then you use the POST action method to retrieve the entered data and save it or call on a save method you created in a repository.