0

In ASP.NET MVC 5 and EF6 Code First, i have a case in which a student can have one to many addresses. Now i want to use Student model in View to add both the record Student and Addresses of student. But the problem is i cant add addresses of student, is there any appropriate solution for this solution

Here is the example code

public class Student
{
    public Student()
    { }

    [Key]
    public int StudentID { get; set; }
    [Required]
    public string Name { get; set; }

    public virtual List<Address> Address { get; set; }
}

public class Address
{
    public Address()
    { 
    }
    [Key]
    public int AddressID { get; set; }
    [ForeignKey("Student")]
    public int StudentID { get; set; }
    public string Address1 { get; set; }
    public string Address2 { get; set; }
    public string PostalCode { get; set; }
    public string State { get; set; }
    public string City { get; set; }
    public string Country { get; set; }

    public virtual Student Student { get; set; }
}
Mano
  • 97
  • 1
  • 12
  • You need jquery to dynamically add the html for new `Address` objects. Refer [this answer](http://stackoverflow.com/questions/28019793/submit-same-partial-view-called-multiple-times-data-to-controller/28081308#28081308) for some examples of how your can approach this –  Feb 27 '15 at 07:38
  • **How** can't you add addresses? Do you mean in the front-end, the back-end, are they not saved, ...? – Gert Arnold Feb 27 '15 at 08:28
  • @Gert I want to add addresses in Model from Front-end – Mano Feb 27 '15 at 08:34

1 Answers1

-2

Make Listbox for address's and Pass with List that will be really help you and can you paste controller code here?

Shahzad Khan
  • 432
  • 2
  • 14