是否可以在 ASP.NET WEBFORM 业务对象类中对 MVC 使用数据注释? [英] Is it possible to use Data Annotations for MVC in an ASP.NET WEBFORM Business Object Class?

查看:14
本文介绍了是否可以在 ASP.NET WEBFORM 业务对象类中对 MVC 使用数据注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

MVC 示例

使用 System.ComponenModel.DataAnnotation;公开课客户{[必需的][字符串长度(5,20)]公共字符串名字{获取;放;}[必需的][字符串长度(5,20)]公共字符串姓氏 { 获取;放;}}

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

解决方案

不幸的是,WebForms 没有像 MVC 这样的数据注释的本机支持.

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

  1. 系统组件模型asp.net 网络表单的数据注释

  2. 使用数据注释构建 ASP.NET 验证器p>

  3. ASP.NET: WebForms Validation with数据注释

How can I use this convention in an asp.net WEBFORM Business object class?

Example In 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;}
}

I want to use this data annotation in my asp.net webform businessobject class for client validation and server validation.

解决方案

Unfortunately WebForms doesn't have native support of Data Annotations like MVC.

But you can use custom decisions:

  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

这篇关于是否可以在 ASP.NET WEBFORM 业务对象类中对 MVC 使用数据注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆