5

私は今、いくつかのカスタム モデル バインダーを作成しましたが、魔法の文字列に依存するという罠に陥っていることに気付きました。

    if (bindingContext.ValueProvider.ContainsPrefix("PaymentKey"))
    {
        paymentKey = bindingContext.ValueProvider.GetValue("PaymentKey").AttemptedValue;
    }

式を使用して接頭辞名を厳密に入力できるようにしたいのですが、方法がわかりません。助けていただければ幸いです。

ありがとう。

4

1 に答える 1

1

あなたが探しているのはbindingContext.ModelName、コードが次のようになることです。

 if (bindingContext.ValueProvider.ContainsPrefix(bindingContext.ModelName))
    {
        paymentKey = bindingContext.ValueProvider.GetValue(bindingContext.ModelName).AttemptedValue;
    }
于 2010-10-04T11:34:26.610 に答える