namespace Automated_VotingSystem.Models
{
public class DisplayCandidatesList
{
public List<DisplayCandidates>? DisplayCandidateslist { get; set;}
}
}
namespace Automated_VotingSystem.Models
{
public partial class DisplayCandidates
{
public int VoterId { get; set; }
public int? CollegeId { get; set; }
public int? EventId { get; set; }
public int CandidateId { get; set; }
public string? Manifesto { get; set; }
public byte[]? Symbol { get; set; }
public string? Symbol_path { get; set; }
}
}
public List<DisplayCandidates> DisplayCandidateslist { get; set; }
[HttpGet("[action]/{GetAllCandidates}")]
public async Task<DisplayCandidatesList> DisplayAllCandidates()
{
var list_of_candidates = (from c in _context.CandidateTables
join ac in _context.ApprovedCandidateTables on c.CandidateId equals ac.CandidateId
join s in _context.SymbolTables on c.SymbolId equals s.SymbolId
where ac.Approval == true
select new
{
candidate_id = ac.CandidateId,
manifesto = c.Manifesto,
symbol_path = s.Symbol_path
}).ToList();
return list_of_candidates;
}
The 1st snippet is my class, 2nd snippet is my model and 3rd snippet is my Controller. While executing the code I am getting a error after returning list of candidates as
Cannot implicitly convert type 'System.Collections.Generic.List<<anonymous type: int? candidate_id, string manifesto, string symbol_path>>' to 'Automated_VotingSystem.Models.DisplayCandidatesList'