【问题标题】:MVC3 UpdateModel - Setting the Id property is only supported with .NET 3.5MVC3 UpdateModel - 仅 .NET 3.5 支持设置 Id 属性
【发布时间】:2011-12-16 03:32:42
【问题描述】:

在 UpdateModel 中发现错误

“在实体反序列化期间,仅 .NET 3.5+ 支持设置 Id 属性” System.Exception {System.NotSupportedException}

public ActionResult Edit1(Guid id, ActivityResponseConsumerMobile arcm) {
        if (!ModelState.IsValid) {
            SetupDropDowns();
            return View(arcm);
        }

        ActivityResponseConsumerMobile arcmDb = uow.ActivityResponseConsumerMobiles.Single(a => a.Id == id);
        try {
            UpdateModel(arcmDb);
        }
        catch {
            var x = ModelState;
            return View(arcm);
        }

感觉像 SO 问题:MVC2 throws InvalidOperationException in UpdateModel(), trying to update the id field

但我使用的是对象而不是 FormCollection。我使用的 ORM 是 LightSpeed。

【问题讨论】:

    标签: asp.net-mvc-3 lightspeed


    【解决方案1】:

    到目前为止,排除项看起来不错..

    UpdateModel(arcmDb, null, null, new[] {"Id"});
    

    事实证明这不是 MVC 问题,因为我在应用程序的其他地方使用 AutoMapper 时遇到了同样的问题,并且也不得不排除那里的 ID。

       Mapper.CreateMap<ActivityPushConsumerMobile, ActivityPushConsumerMobile>()
                                  .ForMember(dest => dest.EntityState, opt => opt.Ignore())
                                  .ForMember(x => x.Id, y => y.Ignore())
    

    不确定自从它工作以来发生了什么变化。可能从 LightSpeed3 升级到 4。并且正在使用 .NET4 框架。

    【讨论】:

      猜你喜欢
      • 2018-06-04
      • 1970-01-01
      • 2010-10-11
      • 2021-10-06
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 2012-05-12
      相关资源
      最近更新 更多