0

Hi I've a problem with MetadataType with my partial class

In my asp.net mvc project i have a class library (Infrastructure) with a DB directory who contain my partial class scafolded from the DB

Exemple

namespace BibliEasy.Infrastructure.DB
{
    public partial class Series
    {
        public Series()
        {
            Publications = new HashSet<Publication>();
        }

        public int IdSerie { get; set; }

        public string TitreSerie { get; set; }

        public string StatutSerie { get; set; }

        public int? VolumesSerie { get; set; }

        public virtual ICollection<Publication> Publications { get; set; }
    }
}

I add Metadata file for the data annotation

Exemple

namespace BibliEasy.Infrastructure.DB
{
    [MetadataType(typeof(SeriesMetaData))]
    public partial class Series { }

    public class SeriesMetaData
    {
        [Display(Name = "Titre")]
        [Required]
        [StringLength(255)]
        public string TitreSerie { get; set; }

        [Display(Name = "Statut")]
        [Required]
        [StringLength(50)]
        public string StatutSerie { get; set; }

        [Display(Name = "Nombre total de volume")]
        [Range(0, int.MaxValue)]
        public int? VolumesSerie { get; set; }
    }
}

And it don't work, in the view this is the name of Serie's property and not the display from SeriesMetaData and the Validation don't work.

What am I missing?

for information the architecture of my project

Infrastructure class library

  • DB directory

Domaine class library

  • Services directory with the class who contains acces function to DB

Application class library

  • ViewModels directory
  • Services directory who contains controller of view models

MVCApp

  • Areas
  • Controllers
  • Views

1 Answer 1

1

Ok in fact I'm in ASP.NET Core so it's not MetadataType but ModelMetadataTypeAttribute

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.