We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Retrieve Header Text from Data Annotations on Model

One thing that's nice about the built-in HTML Helpers like LabelFor() is that it pulls its text from the Display() Data Annotation attribute if supplied. I had assumed that the Grid would do that for the HeaderText, but I'm not seeing that happening. Is there an easy way of making that happen, or shall I create a Feature Request for it?

3 Replies

RD Rakesh D Syncfusion Team May 14, 2013 10:48 AM UTC

 

Hi Mike,

 

Thank you for using Syncfusion products.

 

Query : Retrieve Header Text from Data Annotations on Model ?

 

We would like to let you know that you can display the HeaderText for a column in Grid by defining the Display() Data Annotation attribute in model. Please refer below code snippet for further details.

 

[Display(Name = "Duration in Hrs")]

        public int Duration { get; set; }

 

For your convenience we have prepared a sample for the above scenario and it is attached below. Please refer to it.

 

Could you please let us know whether this is the requirement you wanted to achieve using Display of Data Annotation ? If not could you please provide us more information on your requirement so that we could sort out the issue and provide you the solution for it. The information provided would be of great help in resolving your issue.

  

Please let us know if you have any concerns.

 

Regards,

Rakesh D

 



GridSample Header Text_3c3d2610.zip


HK Hasan Kosten April 9, 2019 11:39 AM UTC

The specified example file does not exist. 


VN Vignesh Natarajan Syncfusion Team April 10, 2019 11:15 AM UTC

Hi Haasan, 
  
Thanks for using Syncfusion Products. 
 
Grid MVC will support Data annotation attributes. Please refer to the following code snippets: 
 
[EditableOrder.cs] 
public class EditableOrder 
{ 
// Validation set to the orderId and customerId 
[Required(ErrorMessage = "Order ID is required.")] 
public int OrderID 
{ 
get; 
set; 
} 
[Required(ErrorMessage = "Customer  ID is required.")] 
[StringLength(5, ErrorMessage = "Customer ID must be 5 characters.")] 
public string CustomerID 
{ 
get; 
set; 
} 
.. . . 
} 
 
 
Add the following script files to your layout.cs within the head tag. Please refer to the following code snippets: 
 
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> 
  
       <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script> 
 
 
We have prepared the sample for your requirement and the same can be downloaded from the following link: 
 
 
Please get back to us if you have further queries. 
 
Regards, 
Vignesh Natarajan. 
 


Loader.
Live Chat Icon For mobile
Up arrow icon