I'm new to ASP.NET MVC 4 and C # and need help. I created a class Enrollment (discipline)
public class Enrollment
{
public virtual int EnrollmentId { get; set; }
public virtual string Name { get; set; }
public virtual ICollection<Component> Components { get; set; }
}
As you can see, you have a list of components
public class Component
{
public virtual int ComponentId { get; set; }
public virtual int EnrollmentId { get; set; }
public virtual string Name { get; set; }
public virtual Enrollment Enrollment { get; set; }
}
I created controllers and views using EF. I would like to know how I can get a user to select a discipline that already exists and add components to it. Basically what is done is that a user goes to the index of the disciplines and sees all the disciplines, these disciplines have a link that goes to the page of details where the components appear, and wanted that it was possible to create only the components for this discipline . If they know another way, it will do. Thank you in advance.
View Index of enrollments (disciplines):
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
<a href="@Url.Action("Details", new { id = item.EnrollmentId })">@Html.DisplayFor(modelItem => item.Name)</a>
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.EnrollmentId }) |
@Html.ActionLink("Delete", "Delete", new { id=item.EnrollmentId })
</td>
</tr>
}
</table>
View Components Details:
<fieldset>
<div class="display-field">
<table>
<tr>
<th>Name</th>
</tr>
@foreach (var item in Model.Components)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
</tr>
}
</table>
</div>