2014-03-05 170 views
1

如何將參數counter傳遞給我的BindUnbind()函數?Mvc 3將參數傳遞給javascript

<div id="adver-list"> 
     @{ 
      var counter = 1; 
      foreach (var adver in (IEnumerable<string>)ViewBag.AdverImages) 
      { 
       <div class="adver-image"> 
        <img class="uploaded_image" src="@Url.Content(adver)" alt="advertisement"/> 
        <input class="hover-delete" id='@adver' type="button" onclick="DeleteAdver(this)"/> 
       </div> 
       counter += 1; 
      } 
      <script type="text/javascript"> 
       $(document).ready(function() { 
        BindUnbind(counter, 1); // how to pass the counter from the above code? 
       }); 
      </script> 
     } 
</div> 

謝謝!

回答

0

使用@像之前一樣:

<script type="text/javascript"> 
$(document).ready(function() { 
    BindUnbind(@counter, 1); 
}); 
</script> 

Visual Studio中可能會抱怨在逗號語法錯誤,但它會在運行時的罰款。

+0

很酷的工作!謝謝@Rraham :) – naru