How To Display Variable Value In View?

2019-03-02 12:14发布

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>

3条回答
看我几分像从前
2楼-- · 2019-03-02 12:50

Using Razor’s @. Try this code:

@{
    var y = v.GetContestantAverageRatingByContestantId(item.ContestantId);
}
<td>
    @Html.DisplayFor(modelItem => item.District)
</td>
<td>
    @y
</td>
查看更多
叼着烟拽天下
3楼-- · 2019-03-02 13:09

Did you try this?

<td>
     @Html.DisplayFor(modelItem => item.District)
</td>
<td>
     @Html.Raw(v.GetContestantAverageRatingByContestantId(item.ContestantId))
</td>
查看更多
疯言疯语
4楼-- · 2019-03-02 13:11

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)
查看更多
登录 后发表回答