In WebForm days you would have just used ToString to get the text description from the enum all the other examples are about the Display Attribute but its not working for me.In .net core all i want to get is the text of enum
public class FileAttachments {
public enum FileAttachmentType {
[Display(Name = "Vessel")]
Vessel = 21,
[Display(Name = "Person Of Intrest")]
Poi =22,
[Display(Name = "Case")]
Case =23,
[Display(Name = "Passport Documents")]
Passport =25,
[Display(Name = "Certificates")]
Certificates =26,
[Display(Name = "Licenses")]
Licences =27,
[Display(Name = "Witness Statements")]
WitnessStatements =28,
[Display(Name = "Photo Evidence")]
PhotoEvidence =29
}
public int FileUploadTypeValue { get; set; }
}
I am Storing the value in FileUploadTypeValue but when I try to access the help method I have to go for example in the model level FileUploadTypeValue will have the value 22 for POI which should print out on screen for me Person Of Interest which is the Display Name of Poi=22
@foreach (var file in Model) {
<tr>
<td>
<span class="fiv-cla fiv-size-lg fiv-icon-@file.Extension"></span>
</td>
<td>
@HelperMethods.GetDisplayName(@file.FileUploadType)
@file.FileUploadType
</td>
<td>@file.CreatedDate</td>
<td>@file.File</td>
<td>@file.UploadedByUser.FirstName @file.UploadedByUser.LastName</td>
<td><a target="_blank" href="/Uploads/@file.File">View File</a></td>
</tr>
}
In MY Helper Class I have the following
public static string GetDisplayName(this Enum enumValue)
{
return enumValue.GetType()?
.GetMember(enumValue.ToString())?
.First()?
.GetCustomAttribute<DisplayAttribute>()?
.Name;
}
Its this line its not liking what should i be passing to get the string so for 22 I should get Person Of Interest instead of poi
@HelperMethods.GetDisplayName(@file.FileUploadType)