我正在使用ValueInjecter将数据从我的视图模型注入到我的实体框架模型中,对于字符串等非 Id,它的效果很好。出于某种原因,它没有从我的视图中映射选择列表中的 ID,一旦映射它们就会显示为空。任何想法为什么?
[HttpPost]
public ActionResult Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
//inject the view model into db model
Core.Models.User user = new User();
user.InjectFrom(model);
查看模型
[Required(ErrorMessage = "Organization is required")]
[DisplayName("Organization")]
public Guid OrganizationId
{ get; set; }
实体框架模型属性
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public Nullable<global::System.Guid> OrganizationId
{
get
{
return _OrganizationId;
}
set
{
OnOrganizationIdChanging(value);
ReportPropertyChanging("OrganizationId");
_OrganizationId = StructuralObject.SetValidValue(value);
ReportPropertyChanged("OrganizationId");
OnOrganizationIdChanged();
}
}