RIA 服务默认必需属性

发布于 2024-11-15 08:02:19 字数 1072 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无法回应 2024-11-22 08:02:19

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文