亲爱的,

请您能帮我理解非常简单的事情吗

我的班级有模特儿:

public class VendorAssistanceViewModel
{
    public string Name { get; set; }
    public bool Checked { get; set; }
}
public partial class CSModel : IEntity
{
    public CSModel()
    {

        VendorAssistances = new[]
        {
        new VendorAssistanceViewModel { Name = "DJ/BAND" },
        new VendorAssistanceViewModel { Name = "Officiant" },
        new VendorAssistanceViewModel { Name = "Florist" },
        new VendorAssistanceViewModel { Name = "Photographer" },
        new VendorAssistanceViewModel { Name = "Videographer" },
        new VendorAssistanceViewModel { Name = "Transportation" },
        }.ToList();
    }


    public IList VendorAssistances { get; set; }


我有看法:

@model IEnumerable<CSTS.Models.CSModel>

 //some html code...


我想知道如何使用VendorAssistances显示来自Model的复选框阵列吗?
我知道这很简单,我阅读了许多文档,但仍然无法理解

谢谢!

更新

我试图做到以下几点:


进入控制

         public override ActionResult Index(int pageNumber, int pageSize, string   nothing)
  {

  List<VendorAssistanceViewModel> VendorAssistances = new[]
{
new VendorAssistanceViewModel { Name = "DJ/BAND" },
new VendorAssistanceViewModel { Name = "Officiant" },
new VendorAssistanceViewModel { Name = "Florist" },
new VendorAssistanceViewModel { Name = "Photographer" },
new VendorAssistanceViewModel { Name = "Videographer" },
new VendorAssistanceViewModel { Name = "Transportation" },
}.ToList();



我已将Watch添加到VendorAssistances并插入断点,并且该对象的所有时间均为NULL

为什么呢?

最佳答案

您只需要遍历Model.VendorAssistances并为每个VendorAssistanceViewModel发出html代码。您可以使用以下代码:

@foreach(var model in Model)
{
    for(int i=0; i < model .VendorAssistances.Count; i++)
    {
        @Html.CheckBoxFor(x => model.VendorAssistances[i].Name)
    }
}


另请阅读this问题,该问题可以帮助您理解如何将生成的数组发布到操作。

10-04 14:20