我有一个包含2行和4列的HTML表格。每个单元格中的数据来自存储过程。目前,最后一列显示数字,我有一个要显示的图像,但只有在(rejected_question> 0)时才显示,否则它不应显示任何内容。我如何用剃刀完成这项工作。
到目前为止,我已经尝试过这个,下面的代码不起作用:
@foreach (var item in Model)
{
//logic for first three columns..
//fourth column here.
<td align="center">
if(@Html.DisplayFor(modelItem => item.RejectedQuestion) >0)
{
return Html.Raw(string.Format("<text><img height='3' width='3' src="\{0}\" alt="\Image\" /></text>", Url.Content("../../content/images/icon_red_questions_returnedbyreviewer.gif")));
}
</td>
}
答案 0 :(得分:0)
在if语句中创建行
@Html.Raw(string.Format("<text><img height='3' width='3' src="\{0}\" alt="\Image\" /></text>", Url.Content("../../content/images/icon_red_questions_returnedbyreviewer.gif")))
显示它。 view.Execute()返回void,因此您不能包含return语句。
答案 1 :(得分:0)
这就是你要找的东西,可能是:
@foreach (var item in Model)
{
//logic for first three columns..
//fourth column here.
<td align="center">
@if(item.RejectedQuestion > 0)
{
<img height="3" width="3" alt="Image"
src="@Url.Content("~/content/images/icon_red_questions_returnedbyreviewer.gif")" />
}
</td>
}
答案 2 :(得分:0)
我试过这个并且它有效,以防将来有人需要它 :
ASC