私は最後の数日間修正しようとしているこの厄介な問題があります。今は運がない。私はモーダルに変換されたモーダルビューと部分ビューを持つビューを持っています。私は、テーブル内のボタンをクリックするとコントローラに渡すパラメータに基づいて、partialviewにデータを書きます。最初のものはうまくいく、ボタンを呼び出すコントローラ - >コントローラはモデルをpartialviewに渡す - >モーダルが開き、正しいデータがフィールドにある。モーダルモデルを一度しか読み込めません
別のレコードのボタンをクリックすると、モーダルが開き、古いデータが表示されます。コントローラが再度呼び出されていないため、データは更新されません。問題は、シフト+ f5でページをリフレッシュするともう一度動作します。だから、それはキャッシュ問題のようです。モーダル
コード インデックスの他の種類を使用して - 私のモーダル からデータを削除するにはjavascriptのメソッドを呼び出す - 私のコントローラおよび方法 でキャッシュを無効にする - 私はこれまで を試してみた何
ビュー
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-lg-12">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>List of registrations</h5>
<div class="ibox-tools">
@Html.ActionLink("Create New", "Create", null, new { @class = "btn btn-primary btn-xs" })
</div>
</div>
<div class="ibox-content">
<table class="table table-striped" id="datatable">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Date)
</th>
<th>
@Html.DisplayNameFor(model => model.Car.Kenteken)
</th>
<th>
@Html.DisplayNameFor(model => model.DepartureLocation)
</th>
<th>
@Html.DisplayNameFor(model => model.ArrivalLocation)
</th>
<th>
@Html.DisplayNameFor(model => model.Distance)
</th>
<th>
@Html.DisplayNameFor(model => model.Allowance)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Date)
</td>
<td>
@Html.DisplayFor(modelItem => item.Car.Kenteken)
</td>
<td>
@Html.DisplayFor(modelItem => item.DepartureLocation)
</td>
<td>
@Html.DisplayFor(modelItem => item.ArrivalLocation)
</td>
<td>
@Html.DisplayFor(modelItem => item.Distance)
</td>
<td>
@Html.DisplayFor(modelItem => item.Allowance)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.CarId }, new { @class = "btn btn-white btn-sm" })
@Html.ActionLink("Delete", "Delete", new { id = item.CarId }, new { @class = "btn btn-white btn-sm" })
@Html.ActionLink("Copy", "CopyTripRegistrationModal", "TripRegistration", new { registrationId = item.RegistrationID }, new { @class = "img-btn-addnote modal-link btn btn-white btn-sm" })
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
</div>
<div id="modal-container" class="modal fade" tabindex="-1" role="dialog">
<a href="#close" title="Close" class="modal-close-btn">X</a>
<div class="modal-content">
<div class="modal-body"></div>
</div>
Javascriptを
<script>
$(function() {
$('body').on('click', '.modal-link', function (e) {
e.preventDefault();
$(this).attr('data-target', '#modal-container');
$(this).attr('data-toggle', 'modal');
});
$('body').on('click', '.modal-close-btn', function() {
$('#modal-container').modal('hide');
});
debugger;
$("#modal-container").on("hidden.bs.modal", function() {
$(".modal-body").removeData();
});
});
パーシャルビュー
<div class="modal-body">
@using (Html.BeginForm("Create", "TripRegistration"))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.CarId)
<div class="form-group">
@Html.LabelFor(model => model.Date, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => Model.Date, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Date)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DepartureLocation, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DepartureLocation)
@Html.ValidationMessageFor(model => model.DepartureLocation)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DepartureZipcode, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DepartureZipcode)
@Html.ValidationMessageFor(model => model.DepartureZipcode)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ArrivalLocation, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ArrivalLocation)
@Html.ValidationMessageFor(model => model.ArrivalLocation)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ArrivalZipcode, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ArrivalZipcode)
@Html.ValidationMessageFor(model => model.ArrivalZipcode)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Distance, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Distance)
@Html.ValidationMessageFor(model => model.Distance)
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<button type="button" class="btn btn-white" id="cancel">Close</button>
<button type="submit" class="btn btn-primary">Copy registration</button>
</div>
</div>
</div>
}
</div>
コントローラのアクション
[NoCache]
public PartialViewResult CopyTripRegistrationModal(int registrationId)
{
var tripRegistration = _tripRegistrationService.getTripRegistrationById(registrationId);
var tripRegistrationVM = AutoMapper.Mapper.Map<tblTripRegistration, TripRegistrationViewModel>(tripRegistration);
return PartialView("_CopyTripRegistration", tripRegistrationVM);
}
["OutputCache(Duration = 0)]"をコントローラの上部に追加しました。
誰かが私を助けてくれることを願っています!
ビューを読み込むJSコードはどこにありますか? JQueryを使用していますか?もしあなたがいるなら 'cache:false'が定義されていることを確認してください。 –