-2

我有这种情况:

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; }
}

我想根据上面集合中的每个分发者创建一个单选按钮列表。当我选择某个分销商时,我想将该DefaultDistributorId属性填充到 Manager 实体中。我怎样才能做到这一点?

@for (int count = 0; count < Model.Distributors.Count; ++count) {

    @Html.RadioButtonFor(m => m.DefaultDistributorId,
        Model.Distributors[count].DistributorId);
}

有任何想法吗?

4

1 回答 1

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
}
于 2013-07-22T04:38:58.633 回答