Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Html.DisplayText will not actually display text

The following is the first section in the first row of a table on one of my ASP MVC3 Index pages. I've stepped through the code when that page loads, and can see that the evaluation of the conditions is done properly, however not of the "CE" or "PT" displays. I'm pretty new to ASP MVC, can someone help me with the syntax/explain what's going on?

@foreach (var item in Model.Where(i => i.Status != "C")) {
var Id = item.Id;
<tr>
    <td>
    @if (!String.IsNullOrWhiteSpace(item.TableName))
    {
        if (item.TableName.Equals("AgentContEd"))
        {
            @Html.DisplayText("CE");
        }
        else if (item.TableName.Equals("AgentProductTraining"))
        {
            @Html.DisplayText("PT");
        }
        else
        {
            @Html.DisplayFor(modelItem => item.TableName)
        }             
    }           
    </td>
like image 464
NealR Avatar asked Jan 17 '13 20:01

NealR


2 Answers

use @: or <text></text> to specify html text inside a server side code if you do not have any other html in there.

if (item.TableName.Equals("AgentContEd"))
{
    @:CE
}
else if (item.TableName.Equals("AgentProductTraining"))
{
    <text>PT</text>
}
like image 200
Dmitry Efimenko Avatar answered Oct 28 '22 17:10

Dmitry Efimenko


There are like 5 different ways of displaying text. In order to display a string you need to use

@Html.DisplayName(string)
like image 19
vincent de g Avatar answered Oct 28 '22 16:10

vincent de g