我試圖通過@onChange將@ item.Id發送到JavaScript函數。但是,當我像下面的代碼那樣編寫它時,JavaScript函數會將它作爲純文本讀取。在html.dropdownlistfor onchange中發送表格中當前項目的標識
剃刀頁:
<table class="table-striped">
<thead>
<tr class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<th class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
<i class="fa fa-sort" title="Blocknummer"></i>
</th>
<th class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
<i class="fa fa-tag" title="Namn på block"></i>
</th>
<th class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
<i class="fa fa-clock-o" title="Längd på block"></i>
</th>
<th class="col-lg-5 col-md-5 col-sm-5 col-xs-5">
<i class="fa fa-user" title="Extern aktör"></i>
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.CourseBlocks)
{
<tr class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<td class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
@Html.DisplayFor(m => item.BlockOrder)
</td>
<td class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
@Html.DisplayFor(m => item.BlockName)
</td>
<td class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
@Html.DisplayFor(m => item.DisplayLength)
</td>
<td class="col-lg-5 col-md-5 col-sm-5 col-xs-5">
@if (item.NeedExternActor)
{
@Html.DropDownListFor(model => item.ExternActorId, new SelectList(Model.ContactPersons, "Value", "Text"), new { @class = "form-control form-control-280 input-sm", @onChange = "actorChange('@item.Id', this.options[this.selectedIndex].value)" })
}
</td>
</tr>
}
</tbody>
</table>
的JavaScript:
function actorChange(id, value) {
var itemId = id;
var actorId = value;
}
預先感謝所有幫助我能。
已經嘗試過。當我試圖說我得到了錯誤「about:blank:546 Uncaught SyntaxError:Invalid or unexpected token」@Zebra – MrKrantz