0

UpdateModel でキャッチされたエラーの取得

「Id プロパティの設定は、エンティティの逆シリアル化中に .NET 3.5 以降でのみサポートされています」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);
        }

質問: MVC2 は UpdateModel() で InvalidOperationException をスローし、id フィールドを更新しようとしています

FormCollection の代わりにオブジェクトを使用しています。私が使用しているORMはLightSpeedです。

4

1 に答える 1

0

除外を入れることで、これまでのところ見栄えが良い..

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

アプリの他の場所で AutoMapper を使用して同じ問題が発生し、そこでも ID を除外する必要があったため、これは MVC の問題ではないことが判明しました。

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

それが機能してから何が変わったのかは不明です。LightSpeed3 から 4 へのアップグレードの可能性があります。.NET4 フレームワークを使用しています。

于 2011-10-27T01:45:36.013 に答える