question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not working with ModelMetaDataType Attribute

See original GitHub issue

I am using Elect.Web.DataTable to generate datatable response.

I have a ef core generated class like this

public partial class Employee
{
       public Employee()
        {
            EmpSalary = new HashSet<EmpSalary>();
            Loan = new HashSet<Loan>();
            PfContribution = new HashSet<PfContribution>();
        }
        public long EmpId { get; set; }

        public string EmpFirstName { get; set; }
        
        public string EmpLastName { get; set; }
        
        public string EmpStreet { get; set; }
        
        public string EmpCity { get; set; }
}

And decorated properties of this class like this

[ModelMetadataType(typeof(IEmployeeMetadata))]
    public partial class Employee :IEmployeeMetadata
    {
        [DataTable(DisplayName = "Name")]
        public string FullName { get { return this.EmpFirstName + " " + this.EmpLastName; } }
    }

    public interface IEmployeeMetadata
    {
        [DataTable(IsVisible = false)]
        long EmpId { get; set; }

        [DataTable(DisplayName = " First Name")]
        [DisplayName("First Name")]
        string EmpFirstName { get; set; }
    }

DisplayName attribute on property “EmpFirstName” works good on view page with @Html.EditorFor, but DataTable attributes are not working.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
gauravsingh8026commented, Jun 1, 2020

Looks good now.

Thanks for the help 👍

0reactions
topnguyencommented, Jun 1, 2020

Hi @gauravsingh8026 , I fixed the issue in ver https://www.nuget.org/packages/Elect.Web.DataTable/3.0.5.2

My mistake on checking the Attribute.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core MetaDataType Attribute not working
The only work-around I've found to work (for me) is to create a new class that wraps the model you're wanting to annotate....
Read more >
Microsoft.AspNetCore.Mvc.ModelMetadataType doesn't work ...
TryValidateObject(), but there is no validation metadata. If I add the validation attributes directly to the generated entity, it works. But, of ...
Read more >
MetadataType not working to merge metadata having followed ...
MetadataType not working to merge metadata having followed Microsoft tutorial for data first approach. I have tried to simplify this problem ...
Read more >
C# – ASP.NET Core MetaDataType Attribute not working
NET Core MetaDataType Attribute not working. asp.net-corec++data-annotations. I'm using the MetaDataType Attribute on my domain model class.
Read more >
ASP.NET Core MetaDataType Attribute not working-.net-core
Although this works for a class with annotations, it doesn't work (for me) for partial classes using either [MetadataType] or [ModelMetadataType] attributes ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found