[英]Casting int to enum value in razor view
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
这是我班上可以为空的int
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 :
我尝试解决您的问题,我认为这可能是一个很好的解决方案:在razor中:
@{var currentStatus = (SMSTaskStatus) item.Status;}
<td>@currentStatus</td>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.