I have a select that takes UserName as value and FirstName + LastName as Text. User is not required to enter first and last namem so I want the select to show UserName (which is the email use for registration) if FirstName and LastName are empty. I tried the below variant but is not working properly, it either gives only UserName for all or empty spaces
C#
MemberList = await _context.UsersData.Where(s => s.OrgID == orgid).Select(s => new
SelectListItem
{
Value = s.UserName,
Text = s.FirstName + " " + s.LastName == null ? s.UserName : s.FirstName + " " + s.LastName
}).ToListAsync();

Sachin SinghRank #66 · 26.2K reputationPosted Jul 26, 2021, 1:38 PM EDT
Marius VasileRank #785 · 2.9K reputationPosted Jul 26, 2021, 1:57 PM EDT
Rijwan AnsariRank #82 · 24.2K reputationPosted Jul 27, 2021, 1:03 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Jul 27, 2021, 6:03 AM EDT
Marius VasileRank #785 · 2.9K reputationPosted Jul 26, 2021, 1:42 PM EDT
Marius VasileRank #785 · 2.9K reputationPosted Jul 27, 2021, 6:31 AM EDT
Marius VasileRank #785 · 2.9K reputationPosted Jul 27, 2021, 6:36 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Jul 27, 2021, 6:59 AM EDT