I've result set as following,
Raw View
Into Array
How to convert List Raw View into List of Array?
I've result set as following,
Raw View
Into Array
How to convert List Raw View into List of Array?
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()?
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()
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;
}

The return type is List<T>
9 people are following this question.
view Component rendered early not waiting for await methods result in asp.net core
Continue processing a file after shows a message for the user
Setting Currency independent of culture
How to redisplay the current view and conditionally set a variable?
Classes Added Using GenerateSchema Appear in the Swagger UI But Not in swagger.json