I am drawing a blank here.. I am using MVC and my model doesn’t have the Value Name, it just has the ID.
The problem is with ‘itm.DegreeTypeId’ it is just an int. But I need to match it up with a string name.. so DegreeTypeId 1 = Associates Degree, 2 = Bachelor, 3 = MBA etc.
I don’t want to update the model to have the name, but instead to a quick lookup. What’s the best way to proceed here? I know I can create a method and have it return the string based on a number but there has to be a better cleaner way.
string education = string.Empty;
int eduCount = 0;
foreach (var itm in candidate.Educations)
{
if (eduCount > 0) education += "<br><br>";
education += string.Format("<b>{0}</b><br>{1} {2}<br>{3}Graduated: {4}<br>",
itm.DegreeTypeId,
itm.InstitutionName,
itm.InstitutionLocation,
itm.GraduatedOn.HasValue
? string.Format("{0:MMMM yyyy}", itm.GraduatedOn.Value)
: string.Empty);
eduCount++;
}
Try using a Dictionary
So the relevant snippet looks like this: