我有對象的列表<>,併爲每個對象,我創建一個表中的一行:根據Counter修改控件名稱?
@for(int cnt=0; cnt< Model.Transaction.TransactionLines.Count; cnt++)
{
<div class="form-group">
<label for="@("cmbCategory" + cnt.ToString())" class="col-lg-1 control-label">Category:</label>
<div class="col-lg-3">
@Html.DropDownListFor(x => x.Transaction.TransactionLines[cnt].CategoryId,
new SelectList(Model.TransactionReferences.Categories, "Value", "Text", Model.Transaction.TransactionLines[cnt].CategoryId), "Select one",
new { @onchange = "populateSubCategory(0)", @class = "cmbCategory0 form-control" })
</div>
...
正如你所看到的,但是,在代碼中,我在標記中硬編碼了「0」。我需要這個來反映「for」循環中的Cntr變量的值。
即@onchange = "populateSubCategory(0)"
我怎麼能代替0,以@cntr?