@P Williams , Welcome to Microsoft Q&A, based on your description, I make a test. I also reproduced your problem.
After my attempt, I find that the problem is the namespace.
As usual, If we use database first in asp.net mvc appp, the customer class should be generated like the following:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace WebApplication1
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public partial class Customer
{
public int Id { get; set; }
//[Display(Name = "Customer name")]
public string Name { get; set; }
public string Details { get; set; }
}
}
Then, We could add the CustomerMetaData class and partial Customer class to the namespace directly.
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace WebApplication1
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public partial class Customer
{
public int Id { get; set; }
//[Display(Name = "Customer name")]
public string Name { get; set; }
public string Details { get; set; }
}
[MetadataType(typeof(CustomerMetaData))]
public partial class Customer
{
}
public class CustomerMetaData
{
[StringLength(50)]
[Display(Name = "Customername")]
public string Name;
[StringLength(50)]
[Display(Name = "DetailName")]
public string Details;
}
}
Note: I also noted that you used the same namespace, but we need to use the default namespace(WebApplication1) instead of the model namespace (WebApplication1.Models).
Tested result:
Best regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.