RIA 服务默认必需属性
我有一个 EF4 模型,其中表的列不允许为空。 在 SL 客户端应用程序中,我总是收到“columnName is required”,因为我在 xaml 中绑定了文本框的 [NotifyOnValidationError=True,ValidatesOnExceptions=True]。
我的问题是: 我可以覆盖元数据类中默认所需的错误消息,但如何将其作为自定义验证?我的意思是我不想在密封元数据类中执行此操作:
[Required(ErrorMessage = "Coin English Name Is required")]
[CustomValidation(typeof (CustomCoinVaidation), "ValidateCoinName")]
public string coin_name_1 { get; set; }
我希望将其放在自定义验证方法中,我将为与 coin_name_1 相关的所有类型的错误定义该方法,如下所示:
public static ValidationResult ValidateCoinName(string name, ValidationContext validationContext)
{
if (string.IsNullOrWhiteSpace(name))
{
return new ValidationResult("The Coin Name should be specified", new [] { "Coin Name" });
}
return ValidationResult.Success;
}
为什么?
有两个原因: 1-将所有验证分组为一个容器(以便进一步轻松本地化)。 2-我不希望将 coin_name_1 显示给最终用户,而是有意义的“硬币英文名称”。
第二个问题: 我的 xaml 页面上有一个 ValidationSummary 控件,其中显示所有错误,但显示列“coin_name_1”的原始名称,我怎样才能将其更改为有意义的值。
此致 瓦利德
I have an EF4 model with table's columns doesn't allow null.
At the SL client application I always receieve the "columnName is required" because I have the binding in xaml with [NotifyOnValidationError=True,ValidatesOnExceptions=True] for the textboxes.
My questions is:
I can overide the default required errormessage at the metadata class, but how can I have it as a custom validation? I mean I don't wnat to do this at the sealed metadata class:
[Required(ErrorMessage = "Coin English Name Is required")]
[CustomValidation(typeof (CustomCoinVaidation), "ValidateCoinName")]
public string coin_name_1 { get; set; }
I want to have it inside the custom validation method that I will define for all types of errors regards that coin_name_1, as follows:
public static ValidationResult ValidateCoinName(string name, ValidationContext validationContext)
{
if (string.IsNullOrWhiteSpace(name))
{
return new ValidationResult("The Coin Name should be specified", new [] { "Coin Name" });
}
return ValidationResult.Success;
}
Why?
for two reasons :
1- Group all the validation isdie one container (for easy localization further).
2- I don't want the coin_name_1 to be displayed to the end-user, but a meanigful as "Coin English Name".
Second question:
I have a ValidationSummary control on my xaml page where all the errors are displayed but is displaying the orignal name of the column "coin_name_1" how can I chnge that to be a meanigfil also.
Best regards
Waleed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
A1:
我只是留下了现在正在实施的所需内容..
A2:
我浏览了不同的来源并找到了这篇文章。
它展示了如何设置验证摘要的样式:
http://www.ditran.net/common-things -you-want-know-about-silverlight-validationsummary
我还在异步地实现客户端验证。
问候
A1:
I just left the required as it is implemented right now..
A2:
I went through different sources and find this artical.
It shows how to style the validation summary:
http://www.ditran.net/common-things-you-want-know-about-silverlight-validationsummary
I am also implementing a client-side validation asyncronizly.
Regards