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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Retrieve Data Annotations

Thread ID:

Created:

Updated:

Platform:

Replies:

132357 Aug 28,2017 01:54 PM UTC Aug 31,2017 12:54 PM UTC ASP.NET Core 4
loading
Tags: Grid
James Wilkinson
Asked On August 28, 2017 01:54 PM UTC

Is there a way to use the data annotations from my models to easy the conversion from razor views and reduce the potential errors during entry.  

According to thread 108690 it can be done in ASP.NET MVC(Classic) .  But I can't download the example to check if I am doing something wrong in ASP.NET Core.

Regards
Jim

Michael Gerfen
Replied On August 28, 2017 05:44 PM UTC

I'm facing the same situation.  The aspnet-core documentation is an missing the data-annotation page from aspnetmvc: https://help.syncfusion.com/aspnetmvc/grid/data-annotation.

 


Saravanan Arunachalam [Syncfusion]
Replied On August 29, 2017 06:31 AM UTC

Hi Michael, 
Thanks for contacting Syncfusion’s support. 
We have analyzed your requirement Data annotation on Asp.Net core application with Syncfusion Grid and achieved it by using Html helper on core application that can be refer from the below code example. 
[View] 
@using Syncfusion.JavaScript.Models 
@model IEnumerable<Orders> 
 
@{ 
    Html.EJ().Grid<Orders>("FlatGrid").Datasource(Model).AllowPaging().Render(); 
} 
[Model] 
public class Orders 
    { 
        . . . 
 
        [Display(Name = "Order ID")] 
        public long OrderID { get; set; } 
 
        public string CustomerID { get; set; } 
        [Display(Name = "Emp ID")] 
        public int EmployeeID { get; set; } 
        [Display(Name = "Freight")] 
        public double Freight { get; set; } 
        public DateTime OrderDate { get; set; } 
        [Display(Name = "City")] 
        public string ShipCity { get; set; } 
        [Display(Name = "Country")] 
        public string ShipCountry { get; set; } 
    } 
[Controller] 
public IActionResult Index() 
        { 
            List<Orders> data = GetData(); 
            return View(data); 
        } 
 
And also we have created a sample that can be downloaded from the below link, 
Regards, 
Saravanan A. 


James Wilkinson
Replied On August 29, 2017 03:39 PM UTC

Thanks for the reply. I am using ViewModels that inherit from Models.  It looks like the annotations defined in the Model are available in the View but not the ones from the ViewModel.

I've attached a project that illustrates this.  I created a new project using the latest asp.net core 2.0 templates in VS2017 since I could not actually run your example.  My system attempted to upgrade it and it does not run.  

In the test project, the property "Enabled" is defined in the ViewModel and its annotation is ignored.  The other properties are defined in the Model and are displayed.

Regards

Jim


Attachment: WebApplicationTest_68cc8305.7z

Saravanan Arunachalam [Syncfusion]
Replied On August 31, 2017 12:54 PM UTC

Hi James, 
We have analyzed your provided sample, the cause of the issue is that you have rendered the Grid object based on the view model as base class (Order) instead of using derived class (OrdersViewModel).  
So, we suggest you to render the Grid based on the derived class object which includes both base and derived class annotation properties on the Grid control that can be refer from the below code example. 
{ 
    Html.EJ().Grid<OrderViewModel>("FlatGrid") 
       . . .         
} 
 
Regards, 
Saravanan A. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;