@ Html.DisplayText实际上不会显示文本 [英] @Html.DisplayText will not actually display text

查看:602
本文介绍了@ Html.DisplayText实际上不会显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一个表的第一行中的第一部分上的我的ASP MVC3索引页之一。我已经通过了code踩时页面加载,并且可以看到条件的评估做得好,但不是的CE或PT显示。我是pretty新ASP MVC,有人可以帮助我的语法/解释这是怎么回事?

  @foreach(在Model.Where(VAR我项目= GT;!i.Status =C)){
变种n = item.Id;
&所述; TR>
    &所述; TD>
    @if(!String.IsNullOrWhiteSpace(item.TableName))
    {
        如果(item.TableName.Equals(AgentContEd))
        {
            @ Html.DisplayText(CE);
        }
        否则如果(item.TableName.Equals(AgentProductTraining))
        {
            @ Html.DisplayText(PT);
        }
        其他
        {
            @ Html.DisplayFor(modelItem => item.TableName)
        }
    }
    < / TD>


解决方案

使用 @ <文本>< /文本> 来指定一个服务器端的code里面的html文本,如果你没有任何其他的HTML在那里。

 如果(item.TableName.Equals(AgentContEd))
{
    @:CE
}
否则如果(item.TableName.Equals(AgentProductTraining))
{
    <文字和GT; PT< /文字和GT;
}

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>

解决方案

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

这篇关于@ Html.DisplayText实际上不会显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆