我有这种情况:
public class Manager {
public int DefaultDistributorId { get; set; }
public List<Distributor> Distributors { get; set; }
}
public class Distributor {
public int DistributorId { get; set; }
public string DistributorName { get; set; }
}
我想根据上面的集合中的每个分销商创建一个radiobutton列表。当我选择一些经销商时,我想将DefaultDistributorId
属性填充到Manager实体中。我怎样才能做到这一点?
@for (int count = 0; count < Model.Distributors.Count; ++count) {
@Html.RadioButtonFor(m => m.DefaultDistributorId,
Model.Distributors[count].DistributorId);
}
有什么想法吗?
答案 0 :(得分:0)
它正常工作
@using (Html.BeginForm("TheAction", "TheController"))
{
foreach (Distributor t in Model.Distributors)
{
@Html.RadioButtonFor(m => m.DefaultDistributorId, t.DistributorId)
}
<input type="submit" value="Submit" />
}
[HttpPost]
public ActionResult Save(Manager model)
{
// You have selected Distributor in model.DefaultDistributorId
}