0
我有一個表
在MVC觀點是這樣的:MVC 5 - 上表行單擊打開彈出與通過視圖模型
@model FoodCalculator.Models.MealViewModel
@{
ViewBag.Title = "Show Meals";
}
<h2>Meals</h2>
<table class="table table-striped table-hover mealDetailsTable">
<thead>
<tr>
<th>
No
</th>
<th>
Meal name
</th>
<th>
Meal type name
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Meals)
{
<tr id="tableRowClick" data-toggle="modal" data-id="@item.Value" data-target="#mealModal">
<td>
@Html.DisplayFor(modelItem => item.Value.MealID)
</td>
<td>
@Html.DisplayFor(modelItem => item.Value.MealName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Value.MealType.MealTypeName)
</td>
<td>
<button class="btn btn-primary" data-toggle="modal" data-target="#mealModal">Details</button>
}
</tbody>
</table>
而且在一排點擊彈出窗口顯示了:
@model FoodCalculator.Models.MealViewModel
<div class="modal fade" id="mealDetails" style="display: none; border: 5px solid black; padding: 10px;" role="dialog" aria-labelledby="CmapModalLabel" 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">Meal details</h4>
</div>
<div class="modal-body">
<input type="text" id="mealID" name="mealDetail" style="display: none;" />
@if (Model != null)
{
<h3> Meal id : @Model.SelectedMealID</h3>
@Html.Action("ShowMealDetails", "Home", new { mealID = Model.SelectedMealID })
}
關閉 保存更改
這一切都是由啓用javascript:
$('.mealDetailsTable').find('tr[data-id]').on('click', function() {
$('#mealDetails').modal('show');
var getIdFromRow = $(event.target).closest('tr').data('id');
$("#mealID").val(getIdFromRow);
});
而且我想要做的就是通過與目前點擊行數據視圖模型到彈出,這樣我就可以進行進一步的行動。
請幫忙!!!!