我有一個頁面,顯示一個僱員名稱ID等表。有編輯鏈接與每個項目。當用戶點擊編輯鏈接時,它會打開一個包含員工詳細信息的新模式框。 模式窗口與父窗口具有相同的模型。事實上,我將相同的模型傳遞給模態窗口。MVC如何傳遞和讀取動態生成的行的ID值
請注意,當用戶點擊編輯鏈接時,我不想調用任何操作方法。當單擊編輯按鈕時,我只顯示詳細信息(在文本字段中)。當用戶在編輯後點擊保存按鈕,然後我調用動作來更新數據庫。
我使用的代碼第一種方法
請考慮下面的代碼
@model IEnumerable<WebApplication1.Models.employee>
......
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.name)
</td>
<td>
@Html.DisplayFor(modelItem => item.age)
</td>
<td>
@Html.DisplayFor(modelItem => item.address)
</td>
<td>
@* I want to pass the value of employee ID when user click this link *@
<a data-toggle="modal" data-target="#myModal" id="editlink1" >Edit..</a>
</td>
</tr>
}
//////
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
Name of the Employee clicked is <TODO>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
我想知道如何在編輯鏈接單擊時傳遞員工ID,以及如何訪問Modal窗口中傳遞的值。
請注意模型索引&模態窗口是一樣的,這是因爲在模態窗口中我有選項移動到下一個記錄。
我們在哪裏你'jQuery'代碼? – Satpal
對不起,我是Jquery和MVC的新手。我還沒有爲此編寫任何jQuery代碼,實際上我想知道如何傳遞可以在Modal窗口中訪問的ID。我們可以用Jquery做這個嗎? –