Kishore

Kishore

  • NA
  • 65
  • 8.6k

PIVOT the data and display in MVC view

Apr 15 2020 9:58 AM
I am trying to display the data in Pivot in MVC view. How to pivot the data by date wise and display the results with header and the values against each result. After getting the data from Procedure I am grouping by Heading and framing the model as follows. My model is as below
  1. public class ResultModel    
  2. {    
  3.     public string ResultName { getset; }    
  4.     public int ResultId { getset; }    
  5.     public double? Score { getset; }    
  6.     public string ResultDate { getset; }    
  7. }    
  8.     
  9. public class ResultGroupViewModel    
  10. {    
  11.     public string Heading { getset; }    
  12.     public List<ResultModel> ResultModel { getset; }    
  13.     
  14. }    
  15.     
  16. public List<ResultGroupViewModel> GetData()    
  17.     {    
  18.         List<ResultGroupViewModel> resultGroupViewModel = new List<ResultGroupViewModel>();    
  19.         for (int i = 1; i <= 5; i++)    
  20.         {    
  21.             ResultGroupViewModel resultViewModel = new ResultGroupViewModel();    
  22.             resultViewModel.Heading = "Heading" + i.ToString();    
  23.             resultViewModel.ResultModel = new List<ResultModel>();    
  24.     
  25.             for (int j = 1; j <= 5; j++)    
  26.             {    
  27.                 resultViewModel.ResultModel.Add(new ResultModel()    
  28.                 {    
  29.                     ResultId = j,    
  30.                     ResultName = "ResultName" + j,    
  31.                     Score = double.Parse(j.ToString()),    
  32.                     ResultDate = string.Format("{0:MM/dd/yy}", DateTime.Now.AddDays(double.Parse(j.ToString())))    
  33.                 }); ;    
  34.             }    
  35.             resultGroupViewModel.Add(resultViewModel);    
  36.         }    
  37.         return resultGroupViewModel;    
  38.     }    
  39. }   
I am trying to display the result in view as follows
https://i.stack.imgur.com/rgXEU.png

Answers (1)