Is it possible to use Data Annotations for MVC in an ASP.NET WEBFORM Business Object Class?

前提是你 提交于 2020-01-22 09:45:29

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/6971079/is-it-possible-to-use-data-annotations-for-mvc-in-an-asp-net-webform-business-ob

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!