I use MVC 3 and EF 4.3.1.
I have my class created with POCO and I’m using Metadata to add DataAnnotations on my properties.
I’m generating Controls and Views using Scaffolding EF.
My problems:
-
Testing the website the OptionId (is a PK IDENTITY) appear as a TextField. I need hide this propertyand make sure the value is created automatically.
-
[StringLength(256)] does not work and in the View there is not ClientValidation
What I’m doing wrong here?
Thanks for your help on this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
namespace MyProject.Models
{
[MetadataType(typeof(ReOptionMetaData))]
public partial class ReOption
{
private class ReOptionMetaData
{
[Key]
public int OptionId { get; set; }
[Required]
[StringLength(64)]
public string Name { get; set; }
public string Value { get; set; }
[Required]
[StringLength(256)]
public string Description { get; set; }
[StringLength(256)]
public string NoteInternal { get; set; }
}
}
}
In the metadata you could use the
HiuddenInputattribute which will generate a hidden input instead of a text field:Make sure you have included
jquery.validate.jsandjquery.validate.unobtrusive.jsscripts to your page.and that you have enabled unobtrusive client script validation in your web.config: