wtm 版本是 5.0.8
按照视频教程里面的方法,提交以后提示如下图
我调试的时候发现 EntityList 为空,应该是没有读取到 excle 的数据,为什么会出现这种情况呢,是哪里写的不对吗?
我把模型中的名称 [Required(ErrorMessage = "{0}是必填项")] 这行代码注释掉就可以导入了,这是不是框架的问题?
public class Area : TreePoco<Area>
{
[Display(Name = "区域名称")]
[Required(ErrorMessage = "{0}是必填项")]
public string Name { get; set; }
[NotMapped]
public string Sheng { get; set; }
[NotMapped]
public string Shi { get; set; }
[NotMapped]
public string Qu { get; set; }
}
public partial class AreaTemplateVM : BaseTemplateVM
{
[Display(Name = "省")]
public ExcelPropety Sheng_Excel = ExcelPropety.CreateProperty<Area>(x => x.Sheng);
[Display(Name = "市")]
public ExcelPropety Shi_Excel = ExcelPropety.CreateProperty<Area>(x => x.Shi);
[Display(Name = "区")]
public ExcelPropety Qu_Excel = ExcelPropety.CreateProperty<Area>(x => x.Qu);
protected override void InitVM()
{
}
}
public class AreaImportVM : BaseImportVM<AreaTemplateVM, Area>
{
public override bool BatchSaveData()
{
this.SetEntityList();
List<Area> newList = new List<Area>();
var shengs = EntityList.Select(x => x.Sheng).Distinct();
foreach (var sheng in shengs)
{
Area c = new Area
{
Name = sheng
};
newList.Add(c);
var shis = EntityList.Where(x => x.Sheng == sheng).Select(x => x.Shi).Distinct();
foreach (var shi in shis)
{
Area c2 = new Area
{
Name = shi,
Parent = c,
ParentId = c.ID
};
newList.Add(c2);
var qus = EntityList.Where(x => x.Sheng == sheng && x.Shi == shi && x.Qu != "市辖区").Select(x => x.Qu).Distinct();
foreach (var qu in qus)
{
Area c3 = new Area
{
Name = qu,
Parent = c2,
ParentId = c2.ID
};
newList.Add(c3);
}
}
}
this.EntityList = newList;
return base.BatchSaveData();
}
}