我有这个令人讨厌的问题,我一直试图修复过去的几个晚上。尽管目前还没有运气。我有一个模态和局部视图的视图,它被渲染到模态中。在单击表格中的按钮时,我使用基于传递给我的控制器的参数填充分数视图。第一个很好,按钮调用控制器 - >控制器将模型传递给partialview - >模式打开并且正确的数据在字段中。在模态中加载模型只能使用一次
当我点击另一条记录上的按钮时,将打开模式并显示旧数据。控制器不再被调用,所以数据不刷新。事情是,如果我用shift + 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'定义。 –