This is a really elementary question and I have searched for an answer but there seems to be none to be found. This is dealing with the Scaffolded MVC5 edit.cshtml using VS2015.
I have a 1:M relationship between 2 tables, and the child table has a @Html.DropDownList as a foreign key to the parent. I need to filter that @Html.DropDownList. These are the specifics:
One AssociationList has many AgsweepParameters.
The primary key of AssociationList is AssociationListId Therefore the AssociationListId field is the Foreign key in the AgsweepParameter table.
Using EntityFramework, and MVC5 Scaffolding, I created the crud views/controllers using Entity Framework as the model.
The generated declaration for that dropdown looks like this:
<div class="form-group">
@Html.LabelFor(model => model.AssociationListId, "Association:", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("AssociationListId", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.AssociationListId, "", new { @class = "text-danger" })
</div>
</div>
Question: How do I filter that dropdown list so that AssociationList.AssociationType=="ACA"?
Note that I use a similar filter on the Index.cshtml on AssociationList table which looks like this:
@foreach (var item in Model.Where(row=>row.AssociationType=="ACA")) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.AssociationListId }) |
@Html.ActionLink("Delete", "Delete", new { id=item.AssociationListId })
</td>
</tr>
}