在HTML表格中显示/隐藏图像

时间:2016-03-05 20:40:29

标签: javascript c# html asp.net-mvc

在我看来,我有一个简单的表格,显示了一些工作流程。 '状态'财产可以显示'失败'或者'成功'。我想要' Succeeded.png'显示所有成功的运行和' Failed.png'对于所有失败的运行。

我该怎么做?



@foreach (var item in Model)
        {
            <tr class="myToolTip" data-toggle="tooltip" data-html="true" title="" data-placement="left">
                <td>                  
                    <span><img src="~/Content/Img/Failed.png" id="failedLogo"/></span>
                    <span><img src="~/Content/Img/Succeeded.png" id="successLogo" /></span>
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Status).
                </td>
		<td>
                    @Html.DisplayFor(modelItem => item.Name)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.CorrelationId)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.StartTime)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.EndTime)
                </td>
                <td>
                    <a href="@Html.DisplayFor(modelItem => item.InputUri)">Input Uri</a>
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.InputContentSize)@{WriteLiteral("Kb");}
                </td>
                <td>
                    <a href="@Html.DisplayFor(modelItem => item.OutputUri)">Output Uri</a>
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.OutputContentSize)@{WriteLiteral("Kb");}
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Error)
               </td>

            </tr>
                        }

    </table>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:1)

您可以这样做:

<img src='@(item.Status=="Succeeded" ? "Succeeded.png" : "Failed.png")' alt='status' />

答案 1 :(得分:0)

首先将列结果转换为图像,然后在适用的位置显示图像。例如:

    <html>
<head>
    <meta charset="utf-8">
    <title>Tutorial: Hello dgrid!</title>
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/resources/dojo.css">
    <link rel="stylesheet" href="djgrid.css">
    <link rel="stylesheet" href="claro.css">
</head>
<body class="claro">
    <div id="grid"></div>


    <!-- load Dojo -->

    <script src="dojo/dojo.js" data-dojo-config="async: true"></script>
    <script src="dojoconfig.js"></script>
    <script>

      require([ 'dgrid/Grid', 'dojo/domReady!' ], function (Grid) {
    var data = [
        { first: 'Bob', last: 'Barker', age: 89 },
        { first: 'Vanna', last: 'White', age: 55 },
        { first: 'Pat', last: 'Sajak', age: 65 }
    ];

    var grid = new Grid({
        columns: {
            first: 'First Name',
            last: 'Last Name',
            age: 'Age'
        }
    }, 'grid');
    grid.renderArray(data);
});
    </script>
</body>
</html>

然后您可以使用 $ image 作为结果显示在您的表格中。

答案 2 :(得分:0)

添加了一个if语句而且它有效!