开发者

MVC 3 - Razor - Print value from model

I am trying to set the value of a label using Razor, I have a model and

<label id="status">
@{ 
if (Model.Count() > 0)
{
   Model.First().StatusName.ToString();
}                                                                   
}
</label>

If I put a breakpoint on Model.First().StatusName.ToString(); I can see that that expressi开发者_如何学Pythonon has the value that I need, but I cannot see it when the page gets rendered - Am I missing something in my syntax ?

Thank you


You need to add @ sign before Model.First().StatusName.ToString() to let Razor know that you are outputting something. Otherwise it will treat it as ordinary method call.

<label id="status">
@{ 
if (Model.Count() > 0)
{
   @Model.First().StatusName.ToString()
}                                                                   
}
</label>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜