【问题标题】:Is it possible to use Data Annotations for MVC in an ASP.NET WEBFORM Business Object Class?是否可以在 ASP.NET WEBFORM 业务对象类中使用 MVC 的数据注释?
【发布时间】:2011-08-07 06:11:46
【问题描述】:

如何在 asp.net WEBFORM 业务对象类中使用此约定?

MVC 中的示例

using System.ComponenModel.DataAnnotation;

public class Customer
{
    [Required]
    [StringLength(5,20)]
    public string FirstName { get; set;}

    [Required]
    [StringLength(5,20)]
    public string LastName { get; set;}
}

我想在我的 asp.net webform businessobject 类中使用此数据注释进行客户端验证和服务器验证。

【问题讨论】:

    标签: asp.net webforms


    【解决方案1】:

    不幸的是,WebForms 没有像 MVC 这样的数据注释的原生支持。

    但您可以使用自定义决策:

    1. system componentmodel dataannotations for asp.net webforms

    2. Building an ASP.NET Validator Using Data Annotations

    3. ASP.NET: WebForms Validation with Data Annotations

    【讨论】:

    • 感谢您链接我的帖子,并在#1 也是:D
    猜你喜欢
    • 1970-01-01
    • 2010-12-06
    • 2011-03-06
    • 1970-01-01
    • 2011-05-20
    • 2014-05-21
    • 1970-01-01
    • 2011-01-20
    • 2022-10-23
    相关资源
    最近更新 更多