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>
精彩评论