我在 IE9 上使用 MVC 3、c# 在我的控制器中,我有以下 2 个重要的 ActionResul:
public ActionResult EditTrain(String trainid)
{
....
return PartialView(edittrain);
}
[HttpPost]
public ActionResult EditTrain(Train editrain)
{
....
DataContext.SubmitChanges();
return RedirectToAction("Edit", new { id = trainid });
}
在局部视图中,我有以下代码:
@model Models.EditTrain
@{
ViewBag.Title = "Training";
}
<h2>Train</h2>
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "theForm" }))
{
@Html.ValidationSummary(false)
@Html.HiddenFor(model => model.ID)
<div class="display-label" style="font-weight: normal">
@Html.Label("ID:")
</div>
<div class="display-field">
@Html.DisplayFor(model => model.ID)
</div>
<div class="display-label" style="font-weight: normal">
@Html.Label("KitID:")
</div>
<div class="display-field">
@Html.DisplayFor(model => model.KitID)
</div>
<div class="editor-label">
@Html.Label("Inactive:")
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Inactive)
</div>
<div class="editor-label">
@Html.Label("Inactive Date:")
</div>
<div id='datepicker' class="editor-field">
@Html.EditorFor(model => model.InactiveDate)
</div>
......
<div style="clear:left;">
<br />
<p>
<input type="submit" id="submit" value="Submit" />
</p>
</div>
}
<script type="text/javascript">
$.ajaxSetup({ cache: false });
$(document).ready(function () {
$("#submit").click(function () {
$.ajax({
type: "POST",
url: url,
data: $('#theForm').serialize()
});
$("#stlist").load('@Url.Action("KitsEdit","Spr")' + '?id=' + '@Model.sprid');
});
});
在上面的代码中,我喜欢上面发生的事情是,一旦用户点击提交,我喜欢它转到以下操作:
[HttpPost]
public ActionResult EditTrain(Train editrain)
然后返回视图并运行以下代码
$("#stlist").load('@Url.Action("KitsEdit","Spr")' + '?id=' + '@Model.sprid');
发生的事情是它执行上述操作但在运行之后
$("#stlist").load('@Url.Action("KitsEdit","Spr")' + '?id=' + '@Model.sprid');
它运行
[HttpPost]
public ActionResult EditTrain(Train editrain)
第二次。
我怎样才能防止它去
[HttpPost]
public ActionResult EditTrain(Train editrain)
在.load() 之后。