Hi,
we are using EF with database first method. When I create new view model, data annotation works fine. But when I put my data annotation in to partial class I was not able to make them work.
Works:
public class TenantViewModel{
[Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int Id { get; set; }
[Required(ErrorMessageResourceName = "msg0004", ErrorMessageResourceType = typeof(Resources.Messages))] [StringLength(Defaults.TenantNameMaxLength, ErrorMessageResourceName = "msg0005", ErrorMessageResourceType = typeof(Resources.Messages))] [Display(Name = "name", ResourceType = typeof(Resources.Translations))] public string Name { get; set; }
[Required(ErrorMessageResourceName = "msg0004", ErrorMessageResourceType = typeof(Resources.Messages))] [StringLength(Defaults.TenantSchemaNameMaxLength, ErrorMessageResourceName = "msg0005", ErrorMessageResourceType = typeof(Resources.Messages))] [Display(Name = "schemaName", ResourceType = typeof(Resources.Translations))] public string SchemaName { get; set; }
}
Do not work:
[MetadataType(typeof(Tenant.TenantMetadata))]
public partial class Tenant
{
private sealed class TenantMetadata
Any idea why? Thanks.
Hello Adam,
Thank you for contacting Infragistics!
I have some questions concerning this matter. Are you displaying the data in the IgniteUI igGrid or another Infragistics control? If it is another control what is the control?
Looking forward to hearing from you.
I am displaying data in text editor:
@(Html.Infragistics().TextEditorFor(model => model.Name)
.ID("tenantName") .Width(200) .NullText(Resources.Translations.name) .ValidatorOptions(options => options.OnBlur(true)) .Value(null) .ReadOnly(false) .Render()
)
When I use view model (TenantViewModel) annotation works (required, length). When I switch to model which is created as partial class (Tenant) the same code does not work.