G-Man
G-Man

Reputation: 7241

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 expression 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

Upvotes: 15

Views: 34890

Answers (1)

Eranga
Eranga

Reputation: 32447

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>

Upvotes: 25

Related Questions