我有一个webgrid,每行都有一个链接,用于打开一个fancybox来修改行。
这是部分视图上的webgrid:
@model IEnumerable<PDSI.Model.Models.Vaccin>
@{
var gridVaccins = new WebGrid(source: Model);
}
@gridVaccins.GetHtml(
tableStyle: "general_table",
columns:
gridVaccins.Columns(
gridVaccins.Column(
columnName: "Vaccin_Type",
canSort: false,
header: "Type"
),
gridVaccins.Column(
canSort: false,
columnName: "Vaccin_Site",
header: "Site",
format: (item) => item.Vaccin_Site.Site
),
gridVaccins.Column(
canSort: false,
columnName: "Date_Recu",
header: "Date reçue",
format: (item) => item.Date_Recu == null ? "" : item.Date_Recu.Date.ToLongDateString()
),
gridVaccins.Column(
canSort: false,
columnName: "Refuse",
header: "Refusé",
format: (item) => item.Refuse ? @Html.Raw("oui") : @Html.Raw("non")
),
gridVaccins.Column(
canSort: false,
header: "",
format: @<a class="editVaccin" href="/Patient/EditVaccin/@item.Id">Modifier</a>
),
gridVaccins.Column(
canSort: false,
header: "",
format: @<a href="/Patient/DeleteVaccin/@item.Id">Supprimer</a>
)
)
)
<script type="text/javascript">
$('a.editVaccin').fancybox();
</script>
当我点击链接时,它会转到此控制器:
public ActionResult EditVaccin(int id)
{
var model = _vaccinServices.GetVaccin(id);
ViewBag.VaccinSite = _vaccinServices.GetVaccinSite();
return PartialView("VaccinEditor", model);
}
我第一次点击它进入控制器以获取我的模型,但在我修改行并从fancybox保存模型并更新表后,如果我再次单击链接“修改器”到修改同一行,它不会进入控制器(EditVaccin)。 href在第二次单击时不起作用。
第二次点击仅使用我们从第一次点击获得的模型信息打开fancybox。
这只发生在IE 8-9中,在Google Chrome中它运行正常,但我必须使用IE。那么我需要做些什么才能让它发挥作用呢?
这是我的webgrid所在的视图:
<div style="width: 100%;">
<a id="addVaccin" href="/Patient/AddVaccin/">Ajouter un vaccin</a>
<br />
<br />
<div id="main_vaccins">@Html.Action("GetVaccins")</div>
</div>
<script type="text/javascript">
$('a#addVaccin').fancybox();
</script>
这是使用webgrid加载局部视图的控制器:
public ActionResult GetVaccins()
{
var listVaccins = _vaccinServices.GetVaccinsByPatient(SessionContext.IdPatient);
return PartialView("VaccinsTable", listVaccins);
}
编辑行的部分视图:
@model PDSI.Model.Models.Vaccin
<script src="../../Scripts/jquery.ui.datepicker.js" type="text/javascript"></script>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Vaccin</legend>
@Html.HiddenFor(model => model.Id_Patient)
@Html.HiddenFor(model => model.Id)
<table>
<tr>
<td>@Html.LabelFor(model => model.Vaccin_Type)
</td>
<td>@Html.TextBoxFor(model => model.Vaccin_Type, new { @maxlength = "20" })
</td>
</tr>
<tr>
<td>@Html.LabelFor(model => model.Vaccin_Site.Site)
</td>
<td>@Html.DropDownList("Vaccin_Site.Id", new SelectList(ViewBag.VaccinSite as System.Collections.IEnumerable, "Id", "Site", Model.Vaccin_Site.Id))
</td>
</tr>
<tr>
<td>@Html.LabelFor(model => model.Date_Recu)
</td>
<td>
@Html.TextBox("Date_Recu", Model.Date_Recu == null ? "" : Model.Date_Recu.Value.ToLongDateString(), new { @class = "date" })
@Html.ValidationMessageFor(model => model.Date_Recu)
</td>
</tr>
<tr>
<td>@Html.LabelFor(model => model.Refuse)
</td>
<td>@Html.CheckBoxFor(model => model.Refuse)
</td>
</tr>
</table>
<p>
<input type="submit" value="Enregistrer" /></p>
</fieldset>
}
<script type="text/javascript">
$(document).ready(function () {
$("#tabs").tabs();
$('.date').datepicker();
});
$('form[action="/Patient/AddVaccin/"]').submit(function (event) {
$.ajax({
url: "/Patient/AddVaccin/",
type: "POST",
dataType: 'html',
data: $('form[action*="/Patient/AddVaccin/"]').serialize(),
success: function (result) {
$.fancybox.close();
$('#main_vaccins').text('');
$('#main_vaccins').html(result);
},
complete: function () {
},
error: function (error) {
alert(error.toString());
}
});
event.preventDefault();
});
$('form[action*="/Patient/EditVaccin/"]').submit(function (event) {
$.ajax({
url: "/Patient/EditVaccin/",
type: "POST",
dataType: 'html',
data: $('form[action*="/Patient/EditVaccin/"]').serialize(),
success: function (result) {
$.fancybox.close();
$('#main_vaccins').text('');
$('#main_vaccins').html(result);
},
complete: function () {
},
error: function (error) {
alert(error);
}
});
event.preventDefault();
});
</script>
编辑的控制器(httpost):
[HttpPost]
public ActionResult EditVaccin(Vaccin model)
{
_vaccinServices.Edit(model);
return RedirectToAction("GetVaccins");
}
感谢您的帮助
答案 0 :(得分:0)
最后这是在做这个工作!
$("a.editVaccin").fancybox({ajax: {cache: false}});
IE保留缓存中的部分视图,为什么第二次点击链接只打开部分视图而不返回控制器。