0

私は奇妙な問題に悩まされています。

jQuery からレンダリングされている MVC ビューにチェック ボックスがあります。

<div>
    <label for="check" class="chk">
        Del ?
    <input id="IsSoftDeleted" name="IsSoftDeleted" data-val-required="The Del? field is required." data-val="true" type="checkbox" class="check"  />
    </label>
</div>

スクリプトは、checked と unchecked の値がオンとオフになるように記述されています。

ボデルバインダーで以下のように処理しました。

protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
    {
        bool softDelete = Convert.ToBoolean(bindingContext.ValueProvider.GetValue("IsSoftDeleted").AttemptedValue != null
                  && bindingContext.ValueProvider.GetValue("IsSoftDeleted").AttemptedValue == "on" ? "true" : "false");


        return OrgFactory.Create(bindingContext.ValueProvider.GetValue("Caption").AttemptedValue,
            bindingContext.ValueProvider.GetValue("NameInUse").AttemptedValue,
            bindingContext.ValueProvider.GetValue("Description").AttemptedValue,
            softDelete, new Party());
    }

これは正常に機能し、組織の IsSoftDeleted プロパティは true または false になりました。

ただし、モデル クラスのブール値で IsSoftDeleted であるため、ModelState は Attempted Value を参照しており、ModelState は false になっています。

AttemptedValue プロパティに値を設定しようとしましたが、アクセスできません。

どうすれば修正できますか?

4

1 に答える 1

-3

冷静になる!!!現在はjQueryで処理しています..

valueprovider クラスを拡張することはできないと思います。

于 2013-06-26T11:43:21.477 に答える