【发布时间】:2010-10-04 10:00:25
【问题描述】:
我现在已经编写了几个自定义模型绑定器,并且意识到我已经陷入了依赖魔术字符串的陷阱,例如:
if (bindingContext.ValueProvider.ContainsPrefix("PaymentKey"))
{
paymentKey = bindingContext.ValueProvider.GetValue("PaymentKey").AttemptedValue;
}
我希望能够使用表达式来强输入前缀名称,但不知道怎么做,希望能得到一些帮助。
谢谢。
【问题讨论】:
-
您可以创建一个静态类来将这些字符串值保存为属性并改为引用这些属性。例如:bindingContext.ValueProvider.ContainsPrefix(SomeClass.PaymentKey)
标签: asp.net-mvc model-binding magic-string