Jump to content


Check out our Community Blogs



Recent Status Updates

View All Updates

Developed by TechBiz Xccelerator
Photo
- - - - -

ASP.NET MVC ANNOTATION

asp.net mvc c#

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 Apprentice123

Apprentice123

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 457 posts

Posted 08 July 2016 - 07:55 AM

I created a class in order to learn about annotation in asp.net. This is my class:

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace MvcMusicStore.Models
{
    [Bind(Exclude = "AlbumId")]
    public class Album
    {
        [ScaffoldColumn(false)]
        public int AlbumId { get; set; }

        [DisplayName("Genre")]
        public int GenreId { get; set; }

        [DisplayName("Artist")]
        public int ArtistId { get; set; }

        [Required(ErrorMessage = "An Album Title is required")]
        [StringLength(160)]
        public string Title { get; set; }

        [Required(ErrorMessage = "Price is required")]
        [Range(0.01, 100.00,
            ErrorMessage = "Price must be between 0.01 and 100.00")]
        public decimal Price { get; set; }

        [DisplayName("Album Art URL")]
        [StringLength(1024)]
        public string AlbumArtUrl { get; set; }

        public virtual Genre Genre { get; set; }
        public virtual Artist Artist { get; set; }
    }
}

But the [DisplayName("Genre")] and [DisplayName["Artist")] aren't working. Also, the Client-Side Validation is not working. When a field is required and I start typing in this field the require message still showing. Where are the problems?



#2 lespauled

lespauled

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1360 posts

Posted 08 July 2016 - 10:45 AM

In order to see why something is or isn't working, we need the view also.


My Blog: http://forum.codecal...699-blog-77241/
"Women and Music: I'm always amazed by other people's choices." - David Lee Roth