0

我在这里问一个类似的问题

所以我OnComplete在 Ajax 表单中添加了一些函数和 Id,并且有:

这是我的观点:

@foreach(var item in Model) {
 <tr id="TR@(item.Id)">
    @{Html.RenderPartial("_PhoneRow", item);}
 </tr>
}

_PhoneRow

@model PhoneModel
@using(Ajax.BeginForm("EditPhone", new { id = Model.Id }, new AjaxOptions {
UpdateTargetId = "TR" + Model.Id,
OnComplete = "OnCompleteEditPhone"
}, new { id = "EditAjaxForm" + Model.Id})) {
<td>@Html.DisplayFor(modelItem => Model.PhoneNumber)</td>
<td>@Html.DisplayFor(modelItem => Model.PhoneKind)</td>
<td><input type="submit" value="Edit" class="CallEditPhone" id="edit@(Model.Id)" /></td>
}

控制器:

public ActionResult EditPhone(long Id) {
  //Get model by id
  return PartialView("_EditPhoneRow", model);
}

public ActionResult SavePhone(PhoneModel model) {
  //Save Phone, and Get Updatet model
  return PartialView("_PhoneRow", model);
}

_EditPhoneRow

    @model PhoneModel
@using(Ajax.BeginForm("SavePhone", new { id = Model.Id }, new AjaxOptions {
UpdateTargetId = "TR" + Model.Id,
OnComplete = "OnCompleteSavePhone"
})) {
<td>@Html.EditorFor(modelItem => Model.PhoneNumber)</td>
<td>@Html.EditorFor(modelItem => Model.PhoneKind)</td>
<td><input type="submit" value="Save" class="SaveEditPhone" id="save@(Model.Id)" /></td>
}

Oncomplete脚本:

function OnCompleteEditPhone() {

$('input.SaveEditPhone').click(function () {
    var id = $(this).attr("id").substring(4);
    $('form#SaveAjaxForm' + id).trigger('submit');
});
}

function OnCompleteSavePhone() {
$('input.CallEditPhone').click(function () {
    var id = $(this).attr("id").substring(4);
    $('form#EditAjaxForm' + id).trigger('submit');
});
}

所以点击编辑工作得很好,然后点击保存也工作得很好,但是当我第二次点击编辑按钮时,我在发布操作中有一个错误,我在这里复制了 Firebug 控制台:

http://Mysite/members/editphone/7652 200 OK 582ms
http://Mysite/members/savephone/7652 200 OK 73ms
http://Mysite/members/editphone/7652 500 internal server error 136ms
<title>The view 'EditPhone' or its master was not found or no view engine supports the searched locations. The following locations were searched: ...

那么问题出在哪里?如果我第二次删除OnCompleteSavePhone了“编辑”按钮不起作用,并且使用此功能出现了一个没有任何意义的错误,我该如何解决?我实际上是通过 Ajax 加载部分视图,并且需要此视图的按钮正常工作,起初一切都很好,但在 Ajax 结果之后他们没有,我想添加一些Oncomplete功能,但也有错误。

4

1 回答 1

0

你之前的问题现在已经回答了。你破坏了标记。因此,您不再需要关心任何OnComplete事件并执行一些自动触发器、表单提交和其他操作。这将由Ajax.BeginForm基础架构自动为您处理。

于 2012-07-07T07:41:00.577 回答