C# 如何编辑模型中的对象列表

C# 如何编辑模型中的对象列表,c#,model-view-controller,C#,Model View Controller,返回控制器时,CustomCssFields为空。我已经设置了一个构造函数,但它仍然是一样的。我发现了一些类似的问题,但它的代码几乎与我的相同 型号 public class CompanyModelView { public CompanyModelView() { CustomCssFields = new List<CompanyCssReferenceModelView>(); } [BsonId] pu

返回控制器时,CustomCssFields为空。我已经设置了一个构造函数,但它仍然是一样的。我发现了一些类似的问题,但它的代码几乎与我的相同

型号

public class CompanyModelView
{
    public CompanyModelView()
    {
        CustomCssFields = new List<CompanyCssReferenceModelView>();
    }
        [BsonId]
        public string _id { get; set; }

        [BsonElement("CompanyName")]
        [DisplayName("Company Name")]
        public string CompanyName { get; set; }

        [BsonElement("CompanyCode")]
        [DisplayName("Company Code")]
        public string CompanyCode { get; set; }

        [BsonElement("CompanyConnectionString")]
        [DisplayName("Company Connection String")]
        public string CompanyConnectionString { get; set; }

        [BsonElement("CargowiseVersion")]
        [DisplayName("Cargowise Version")]
        public string CargoWiseVersion { get; set; }

        [BsonElement("CustomCssFields")]
        [UIHint("CustomCssFields")]
        public IList<CompanyCssReferenceModelView> CustomCssFields { get; set; }
}

public class CompanyCssReferenceModelView
{
        [BsonElement("FieldName")]
        public CssOptionEnum FieldName;

        [BsonElement("FieldValue")]
        public string FieldValue;
}
公共类公司模型视图
{
上市公司模型视图()
{
CustomCssFields=新列表();
}
[BsonId]
公共字符串_id{get;set;}
[b单一元素(“公司名称”)]
[显示名称(“公司名称”)]
公共字符串CompanyName{get;set;}
[b单一元素(“公司代码”)]
[显示名称(“公司代码”)]
公共字符串公司代码{get;set;}
[BsonElement(“公司连接字符串”)]
[显示名称(“公司连接字符串”)]
公共字符串CompanyConnectionString{get;set;}
[B单一元素(“货讯通版本”)]
[显示名称(“货讯通版本”)]
公共字符串版本{get;set;}
[BsonElement(“CustomCssFields”)]
[UIHint(“CustomCssFields”)]
公共IList CustomCssFields{get;set;}
}
公共类公司csreferencemodelview
{
[BsonElement(“字段名”)]
公共CssOptionEnum字段名;
[b单一元素(“字段值”)]
公共字符串字段值;
}
查看 这里是风景

@model WebTrackerModels.CompanyModels.CompanyModelView
    <form asp-action="SaveCompany" enctype="multipart/form-data">
    <div class="form-group">
    <table class="table">
                        <thead>
                            <tr>
                                <th>
                                    Field Name
                                </th>
                                <th>
                                    Field Value
                                </th>
                            </tr>
                        </thead>
        <tbody>
         @{                            
              for (int i = 0; i < Model.CustomCssFields.Count; i++)
              {
                  <tr>
                      <td>                                        
                          @Html.DisplayFor(model => model.CustomCssFields[i].FieldName)
                      </td>
                      <td>
                          @Html.TextBoxFor(model => model.CustomCssFields[i].FieldValue, new { @class = "form-control", type = "color", value = Model.CustomCssFields[i].FieldValue })
                      </td>
                   </tr>
        }
        }
        </tbody>
    </table>
    </div>
          <div class="form-group">
               <input type="submit" value="Save" class="btn btn-success" />
           </div>
    </form>
@model WebTrackerModels.CompanyModels.CompanyModelView
字段名
字段值
@{                            
对于(int i=0;imodel.CustomCssFields[i].FieldName)
@Html.TextBoxFor(model=>model.CustomCssFields[i].FieldValue,新的{@class=“form control”,type=“color”,value=model.CustomCssFields[i].FieldValue})
}
}

是否将CompanyModelView绑定到视图?是,其他字段没有问题。只有CustomCSSFields您如何发布?我在您的视图中没有看到表单。@user10728126等待时间有点长。