I have a problem that I have been trying to figure out and I was hoping for some help. I have the following Model
public class SampleModel
{
[Required]
public int Id {get;set;}
[Required]
public string Name {get;set;}
[Required]
public int TypeId {get;set}
public int? SubTypeId {get;set;}
}
I have the API calls to get All Available Types, then API call to get Available SubTypes based on a passed TypeId.
The Controller has the Index set up that I pass the appropriate set of types in a ViewBag.AvailableTypes
. I also have the Razor View:
@model IEnumerable<Models.SampleModel>
@{
ViewBag.Title = "SetSampleModels";
}
<h2>Set Sample Models</h2>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Id)
</th>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.TypeId)
</th>
<th>
@Html.DisplayNameFor(model => model.SubTypeId)
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.NaME)
</td>
<td>
@Html.DropDownListFor(modelItem => item.TypeId,AvailableTypes)
</td>
<td>
??????@Html.DropDownListFor(.....)?????
</td>
</tr>
}
</table>
I have jquery that can replace a select dropdown on the fly, but I don't know how to code the target for the jquery and have the controller read in the correct item. I also am unfamiliar with how to allow "null" options since I do not require a subtype.
Any help would be greatly appreciated as it is frustrating to solve this.
Thanks all! Jon