CarrotCrop
CarrotCrop

Reputation: 73

How To Display Variable Value In View?

Here I am trying to display variable y value in td in view(i.e .cshtml). But have no idea how to do that.

Below is my view:

<td>
    @Html.DisplayFor(modelItem => item.District)
</td>
<td>
    @{
        var y = v.GetContestantAverageRatingByContestantId(item.ContestantId);
    }
</td>

Upvotes: 4

Views: 22837

Answers (3)

kirtan
kirtan

Reputation: 61

Did you try this?

<td>
     @Html.DisplayFor(modelItem => item.District)
</td>
<td>
     @Html.Raw(v.GetContestantAverageRatingByContestantId(item.ContestantId))
</td>

Upvotes: 0

Rai Vu
Rai Vu

Reputation: 1635

Using Razor’s @. Try this code:

@{
    var y = v.GetContestantAverageRatingByContestantId(item.ContestantId);
}
<td>
    @Html.DisplayFor(modelItem => item.District)
</td>
<td>
    @y
</td>

Upvotes: 0

Salah Akbari
Salah Akbari

Reputation: 39946

There are several ways. For example simply using @ like this:

<td>
    @y
</td>

Or by using a <span> tag like this:

<span>Your Text @(y) ...</span>

Or using Html.Label helper:

@Html.Label("lblName", y)

Upvotes: 8

Related Questions