我在使用jquery取消并恢复到索引部分视图时遇到问题。
所以这就是我想要的功能。如果我添加一行并确定要取消添加行,则需要返回原始的局部视图。发生的是,一旦执行了取消功能,它就会在屏幕上保留添加的行,我只需手动刷新屏幕。我不想做location.reload(true),因为那会刷新整个页面,我只是想让它刷新实际的局部视图。
感谢先进的新鲜眼睛,我一直在看这个,我知道我错过了什么。
功能:
function cancelThis(element) {
var attendeeuserID = $(element).parents().find('.attendee-stored- id').attr('data-value');
getCustomerByID(attendeeuserID, element);
}
function getCustomerByID(id, element) {
GetByID("UserCatalogView/Cancel", id, element);
}
function replaceAttendeeRow(result, element) {
$(element).closest('tr').replaceWith(result);
}
function GetByID(url, id, callback, param1) {
$.ajax({
url: "../../" + url + "/" + id,
type: "POST",
success: function (result) {
if (callback != null && callback != undefined) {
callback(result);
}
},
error: function (result) {
if (result.responseText != '') {
alert(result.responseText);
}
else {
alert("An error occurred while processing results. Please consult an administrator.");
}
}
})
}
控制器:
public ActionResult Cancel (Guid id) //not using this controller at the moment. Just using the window.location to cancel out.
{
CatalogAttendeeModel model = new CatalogAttendeeModel();
model.getAttendeesListByID(id);
var catalog = from ca in db.Catalog_Attendee
join a in db.Attendees on ca.AttendeeID equals a.AttendeeID
where ca.AttendeeID == id
select ca;
foreach (var item in catalog)
{
if (item.IsActive == null)
{
item.IsActive = true;
}
}
return PartialView("Index", model);
}
部分视图:
@{
<tr>
<td>@Html.DropDownList("CatalogEdit")</td>
<td>@Html.DropDownList("StudyRoleEdit")</td>
<td>@Html.EditorFor(item => item.usercatalogs.IsAdmin.Value)</td>
<td>@Html.DropDownListFor(item => item.usercatalogs.IsTrainingDocPrinted, new[] { new SelectListItem { Text = "Yes", Value = "True" }, new SelectListItem { Text = "No", Value = "False" } }, new { style = "width:50px" })</td>
<td></td>
<td></td>
<td>@Html.TextBoxFor(m => m.usercatalogs.PIName, new { @class = "texbox", style = "width:70px" })</td>
<td><img class="savecatalog" style="cursor:pointer" onclick="saveEdit(this)" title="Save" src="@Url.Content("~/Content/Images/save.png")" />
<img onclick="cancelThis(this)" style="cursor:pointer" title="Cancel" src="@Url.Content("~/Content/Images/cancel.png")" />
</td>
</tr> }
答案 0 :(得分:0)
所以我发现在javascript中使用toggle()方法在内联视图之间来回切换。它很棒。因此,例如在我的局部视图中,我可以将我的编辑视图包装在div中,只有在我点击编辑时才显示它,它将显示编辑视图并隐藏索引视图。然后,如果我点击取消,它将隐藏编辑视图并根据onclick取消隐藏索引视图。