2016-12-13 6 views
0

2行4列のHTMLテーブルがあります。各セル内のデータは、格納されたprocから来ています。現在、最後の列には数字が表示されていますが、表示するイメージがありますが、(rejected_question> 0)それ以外の場合は表示されません。どのように私は剃刀でこれを達成するのですか?HTMLテーブル用のかみそり構文の条件 - MVC

私はこれまでのところ、以下のコードは動作しません。これを試してみました:

@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

これはおそらく、あなたが探して何です:

@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> 
} 
+0

私はあなたのアプローチを試しました、それは画像と一緒にif条件を表示する、私は何かが不足していますか? – Hari

+0

Woops。ごめんなさい。 'if'の前に' @ 'を忘れました。私は答えを修正します。 –

+0

申し訳ありませんが、agian Jamesはうまくいきませんでした。エラーは:演算子は、文字列とint型に適用することはできません – Hari

0

それを表示するには、文の

場合
@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文は使用できません。

+0

あなたはこのもしかして:もしを(@ Html.DisplayFor(modelItem => item.RejectedQuestion)> 0) { Html.Raw(string.Format( "\Image\"、Url.Content( "../../ content/images/icon_red_questions_returnedbyreview er.gif "))); }。もしそうなら、それはうまくいかなかった。 – Hari

0

誰かが将来 でそれを必要とする場合、私はこれを試してみました、それが働いた、念のために:

@if(item.RejectedQuestion > 0) 
        { 
        <img height="20" width="20" alt="Image" 
         src="@Url.Content("~/content/images/icon_red_questions_returnedbyreviewer.gif")" /> 
       }