IList&x27;未在viewmodel中发回

IList&x27;未在viewmodel中发回,list,model-view-controller,razor,postback,viewmodel,List,Model View Controller,Razor,Postback,Viewmodel,我有一个MVC页面正在做一些奇怪的事情。我有一个类,它包含两个IList,分支和用户 公共类第三方视图模型 { 公共字符串MessageText{get;set;} 公共分支地址{get;set;} 公共字符串地址BranchCode{get;set;} 公共字符串FullAddressBlock{get;set;} 公共IList第三方用户{get;set;} 公共IList第三方分支{get;set;} 公共字符串BrandStyle{get;set;} }我觉得你的代码不错。可以尝试初始

我有一个MVC页面正在做一些奇怪的事情。我有一个类,它包含两个IList,分支和用户

公共类第三方视图模型
{
公共字符串MessageText{get;set;}
公共分支地址{get;set;}
公共字符串地址BranchCode{get;set;}
公共字符串FullAddressBlock{get;set;}
公共IList第三方用户{get;set;}
公共IList第三方分支{get;set;}
公共字符串BrandStyle{get;set;}

}
我觉得你的代码不错。可以尝试初始化模型默认构造函数中的两个列表。我以前遇到过一个问题,模型绑定器不会创建列表,但如果列表不为null,就会填充列表

public class ThirdPartyViewModel
{
    public String MessageText { get; set; }
    public BranchAddress Address { get; set; }
    public String AddressBranchCode { get; set; }
    public String FullAddressBlock { get; set; }

    public IList<ThirdPartySubUserLine> ThirdPartyUsers { get; set; }
    public IList<ThirdPartyBranch> ThirdPartyBranches { get; set; }
    public String BrandStyle { get; set; }

    public ThirdPartyViewModel()
    {
        ThirdPartyUsers = new List<ThirdPartySubUserLine>();
        ThirdPartyBranches = new List<ThirdPartyBranch>();
    }
}
公共类第三方视图模型
{
公共字符串MessageText{get;set;}
公共分支地址{get;set;}
公共字符串地址BranchCode{get;set;}
公共字符串FullAddressBlock{get;set;}
公共IList第三方用户{get;set;}
公共IList第三方分支{get;set;}
公共字符串BrandStyle{get;set;}
公共第三方视图模型()
{
第三方用户=新列表();
ThirdPartyBranches=新列表();
}
}

我总是在屏幕上填充并显示两个列表,但我并不总是将两个列表都发回。感谢检查生成的html是否具有正确的属性名称,例如:ThirdPartyUsers[0]。UserId。我遇到的另一个问题是,当输入字段在提交之前被禁用时,它们不会包含在post数据中。但是我看不出你是否禁用了任何项目。只是看了一下“查看源代码”。对不起,没问题。所有东西都是唯一的,不可禁用的。您是否尝试在模型中放置一个默认构造函数来初始化这两个列表?这是我使用的模型活页夹的一个问题,即从视图发布到控制器。我在答案中添加了一个示例。如果这不能解决问题,则模型绑定器可能存在问题。