2015-08-03 70 views
0

在一個循環中,我需要將div在第一個循環之後隱藏起來,並將其隱藏起來,並在展開時顯示,簡單正確。如何禁用剃刀與打開和關閉標籤的聰明?

//above this lives code that draws a product section 
       if (product.DisplayOrder == 1 && Model.Count > 1) 
       { 
        <div class="arrow-with-text" style="cursor: pointer;"> 
         <div class="arrow-right"></div> 
         <div class="arrow-down" style="display: none"></div> 
         <div style="margin-left: 2em;margin-top: -1.3em;font-size: 1.2em;color: #2280c4;">Other available Wills…</div> 
        </div> 
       <div class="other-wills" style="display: none"> 
       } 
       else (product.DisplayOrder == Model.Count) 
       { 
        </div> 
       } 

我的預期是什麼先被包裹在other-wills格,然後在最後一個被關閉之後去的所有部分。它實際得到的是這個。

     <div class="arrow-with-text" style="cursor: pointer;"> 
         <div class="arrow-right"></div> 
         <div class="arrow-down" style="display: none"></div> 
         <div style="margin-left: 2em;margin-top: -1.3em;font-size: 1.2em;color: #2280c4;">Other available Wills…</div> 
        </div> 
       <div class="other-wills" style="display: none"> 
       } 
       else (product.DisplayOrder == Model.Count) 
       { 
        </div> 
<div class="sections-wrapper"> 

這不正是我所期待的(它reendered }else product.DisplayOrder == Model.Count){文本)。

enter image description here

如何使剃鬚刀解釋我if聲明的關閉和else是否正確?

+0

試圖'@ else'和'@ if'? –

回答

1

使用

@Html.Raw("</div>") 

@Html.Raw("<div class=\"your-class\">") 

的 '流浪' 動態的div

+0

工作,謝謝。令人驚訝的是,我仍然必須在剃刀代碼段使用'@ Html.Raw'(而不是'Html.Raw')。 Html.Raw不會拋出錯誤,根本不會渲染任何東西。 –

+0

即使你在剃刀區域,我總是認爲@ Html.xxxxx等同於「Response.Write」或「echo」。如果您將生成的HTML分配給Razor代碼中的變量,則會使用省略@符號。 – scgough