ASP.NET MVC 3: Unobtrusive JavaScript Validation

There are many examples of how to "create your own model." Check their DataAnnotations. Scott Guthrie explains how to test his model using ORM . What I do not find is when your model really comes from an external DLL. How do you check it?

Example:

/* Class coming in from an third-party DLL file. */
public class Person
{
    public string Name{get;set;}
    public int Age {get;set;}
}

The solution I'm thinking of: Inherit an external class, and then apply [MetadataType] to the inherited class.

[Metadata(typeof(Person2_Validation))]
public class Person2:Person{}

public class Person2_Validation
{
    [Required,Stringlength(50,ErrorMessage="Name required"]
    public string Name{get;set;}

    [RegularExpression("([0-9]+)")]
    public int Age
}

Is there a better way?

+3
source share
2 answers

Mapper (, AutoMapper EmitMapper ValueInjecter) .

, .

ViewModel ASP.NET MVC.

- :

A ( DLL) B ( )

B .

, , - B. - /, ( ) A = > B (, ).

B , , B = > A /.

BTW: , A .

ViewModels Domain Views.

+4

Source: https://habr.com/ru/post/1796535/


All Articles