asp.net-mvc-3lightspeed

MVC3 UpdateModel - Setting the Id property is only supported with .NET 3.5


Getting an error caught in UpdateModel

"Setting the Id property is only supported with .NET 3.5+ during entity deserialization" 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);
        }

Feels like SO Question: MVC2 throws InvalidOperationException in UpdateModel(), trying to update the id field

but I'm using the object instead of FormCollection. ORM I'm using is LightSpeed.


Solution

  • Looking good so far with putting in an exclusion..

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

    It turns out this is not an MVC issue as I had the same issue using AutoMapper elsewhere in the app, and had to exclude the ID there too.

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

    Unsure as to what has changed since it worked. Possible upgrade from LightSpeed3 to 4. And am using .NET4 framework.