I have an enum that looks like this:
public enum SMSTaskStatus
{
New = 0,
Awaiting = 1,
InProgress = 2,
OnHold = 3,
Done = 4,
Error = 5
}
and I am trying to return the value in a razor view using
<td>@{ (SMSTaskStatus) item.Status.Value;}</td>
but i get an error that
'Only assignment, call, increment, decrement, await and new
object expressions can be used as a statement'
How can I cast it to the enum value in the view? It's a nullable int in my class
public int? Status { get; set; }
As you mentioned before when you try to cast an enum in razor, you get the error. I tried to implement your situation, I think this could be a good solution: In razor :
@{var currentStatus = (SMSTaskStatus) item.Status;}
<td>@currentStatus</td>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.