question

JerryLipan-2008 avatar image
0 Votes"
JerryLipan-2008 asked JaliyaUdagedara edited

What is the different between List into Raw View and List into Array ?

I've result set as following,

Raw View
113019-09072021-001.png


Into Array
113020-09072021-002.png


How to convert List Raw View into List of Array?
113131-09072021-001.png


dotnet-csharpdotnet-aspnet-core-mvc
09072021-001.png (30.5 KiB)
09072021-002.png (75.2 KiB)
09072021-001.png (30.5 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Just for clarification, your question is, you need the result of _employeeDM.GetAll() to be converted to an array, is it? What's the return type of _employeeDM.GetAll()?

0 Votes 0 ·
JaliyaUdagedara avatar image
0 Votes"
JaliyaUdagedara answered JaliyaUdagedara edited

Right, so looking at the code, _employeeDM.GetAll() returns an EmployeeVM which cannot be converted to an array. However I see that it contains a List<EmploeeVM.Employee>, and that can be converted to an array.

For example,

EmployeeVM viewModel = _employeeDM.GetAll();
var employeesArray = viewModel.Employees.ToArray()
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JerryLipan-2008 avatar image
0 Votes"
JerryLipan-2008 answered

Hi @JaliyaUdagedara ,

For return type, see the code

  public class EmployeeController : Controller
     {
         public static List<EmployeeVM> emp = new List<EmployeeVM>();
    
         private IDepartmentDM _departmentDM;
    
    
         private IEmployeeDM _employeeDM;

 public EmployeeController(IDepartmentDM departmentDM, IEmployeeDM employeeDM)
         {
             _departmentDM = departmentDM;
             _employeeDM = employeeDM;
         }
    
            
         public IActionResult Index()
         {            
             ViewBag.DataSource = _employeeDM.GetAll();
               
             return View();
         }
    

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
    
 namespace TAFACoreMvc.Models
 {
     public interface IEmployeeDM
     {
         EmployeeVM GetAll();
     }
 }

This is the method

  public EmployeeVM GetAll()
         {
             var vm = new EmployeeVM();
    
             var dtos = svc.GetAll().ToList();
    
             vm.Employees.AddRange(dtos.Select(dto => new EmployeeVM.Employee()
             {
                 EmployeeId = dto.EmployeeId,
                 DepartmentId = dto.DepartmentId,
                 DepartmentName = dto.DepartmentName,
                 EmployeeName = dto.EmployeeName,
                 Designation = dto.Designation
             }).ToList());
    
             return vm;
         }

113010-09072021-003.png


The return type is List<T>



09072021-003.png (26.2 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.