@Html.DisplayText will not actually display text

前端 未结 4 1090
一生所求
一生所求 2021-01-03 19:51

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

相关标签:
4条回答
  • 2021-01-03 20:11

    The DisplayText is synonomous for Model.PropertyName.. so Model.PropertyName = @Html.DisplayText('PropertyName')

    So if CE is not an attribute of your model, and you are just trying to output raw text than just replace that statement with the raw text:

            if (item.TableName.Equals("AgentContEd"))
            {
                <text>CE</text>
            }
    
    0 讨论(0)
  • 2021-01-03 20:21

    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>
    }
    
    0 讨论(0)
  • 2021-01-03 20:26

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

    @Html.DisplayName(string)
    
    0 讨论(0)
  • 2021-01-03 20:27

    You have to get Razor to realize that you are trying to display literal text. See this good
    Razor syntax guide for more information.

    if (item.TableName.Equals("AgentContEd")) { <text>CE</text> }

    0 讨论(0)
提交回复
热议问题