Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David Zweben 265 posts 749 karma points
    Jul 19, 2018 @ 13:24
    David Zweben
    0

    Error with DataAnnotations

    Hi. I am trying to set up a member registration form in my Umbraco Cloud project, following the Creating a Member Umbraco.TV episode. I created the RegisterModel.cs file, but I am getting errors on my DataAnnotations.

    The type or namespace name 'Required' could not be found (are you missing a using directive or an assembly reference?)

    I am including a using statement for "System.ComponentModel.DataAnnotations", but it is grayed out, suggesting it is not being used, and the "[Required]" and "[EmailAddress]" lines are underlined.

    My full code is below. What could I be doing wrong? Since this is an Umbraco Cloud project, and this Model file exists in a Class Library, do I need to add a specific reference to the Class Library project? Any suggestions would be appreciated.

    using System.ComponentModel.DataAnnotations;
    using System.Web.Mvc;
    
        namespace MyProject.Core.Models
        {
            public class RegisterModel
            {
                [Required]
                public string Name { get; set; }
    
                [Required]
                [EmailAddress]
                public string Email { get; set; }
    
                [Required]
                public string Password { get; set; }
            }
        }
    

    Thanks,
    David

  • David Zweben 265 posts 749 karma points
    Jul 19, 2018 @ 14:02
    David Zweben
    100

    I think I have this fixed. It looks like all I had to do was install the NuGet package "System.ComponentModel.Annotations" to the MyProject.Core project.

Please Sign in or register to post replies

Write your reply to:

Draft