Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用JQuery取消MVC中的单线编辑_Javascript_Jquery_Asp.net Mvc_Partial Views_Reload - Fatal编程技术网

Javascript 使用JQuery取消MVC中的单线编辑

Javascript 使用JQuery取消MVC中的单线编辑,javascript,jquery,asp.net-mvc,partial-views,reload,Javascript,Jquery,Asp.net Mvc,Partial Views,Reload,我在使用jquery取消并恢复到索引部分视图时遇到问题 这就是我想要函数做的。如果我添加一行并决定取消添加该行,它需要返回到原始局部视图。发生的情况是,一旦执行了取消功能,它就会在屏幕上保留添加的行,我只是手动刷新屏幕。我不想执行location.reloadtrue,因为这将刷新整个页面,我只希望它刷新实际的部分视图 感谢你们的新鲜目光,我似乎一直在看着这一切,我知道我错过了什么 功能: function cancelThis(element) { var attendeeuserID = $

我在使用jquery取消并恢复到索引部分视图时遇到问题

这就是我想要函数做的。如果我添加一行并决定取消添加该行,它需要返回到原始局部视图。发生的情况是,一旦执行了取消功能,它就会在屏幕上保留添加的行,我只是手动刷新屏幕。我不想执行location.reloadtrue,因为这将刷新整个页面,我只希望它刷新实际的部分视图

感谢你们的新鲜目光,我似乎一直在看着这一切,我知道我错过了什么

功能:

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>    }

所以我发现使用javascript中的toggle方法在内联视图之间来回切换。它工作得很好。例如,在我的局部视图中,我可以将我的编辑视图包装在一个div中,仅当我点击edit时才显示它,它将显示编辑视图并隐藏索引视图。然后,如果我点击cancel,它将隐藏编辑视图,并根据onclick取消隐藏索引视图

你的意思是你只想把控件重置回原来的默认值吗?@StephenMuecke,一旦它被更新,我希望它基本上只是刷新局部视图以显示添加的行。因此,在返回视图的末尾显示添加的行。这有意义吗?不太有意义。你最后的评论说,一旦它更新,但你的问题谈论取消它。不确定要执行什么操作,但可以使用输入的defaultValue属性将输入重置为默认值,也可以使用$this.closest'tr.remove删除行;