gpt4 book ai didi

asp.net-mvc-3 - ValueInjector 未从 View 模型映射 ID

转载 作者:行者123 更新时间:2023-12-04 06:07:43 25 4
gpt4 key购买 nike

我正在使用 ValueInjecter将数据从我的 View 模型注入(inject)到我的 Entity Framework 模型中,对于诸如字符串之类的非 Id 来说效果很好。出于某种原因,它没有从我的 View 中映射选择列表中的 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; }

Entity Framework 模型属性
    [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();
}
}

最佳答案

这是因为它们的类型不同GuidNullable<Guid>

关于asp.net-mvc-3 - ValueInjector 未从 View 模型映射 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8160286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com