我有以下代码可以打开与视图的对话。
$('.bulkEditlink').click(function () {
var f = $('td:first', $(this).parents('tr')).text();
var r = tableCols().toString();
loadBulkEdit(f, r); //loadBulkEdit is defined on RoleCompare View.
});
--用get加载视图
function loadBulkEdit(f,r) {
var $urlpath = "@Url.RouteUrl(new { area = "Admin", controller = "Role", action = "RoleEntitlementEdit"})";
$.ajax({
url: $urlpath,
type: 'GET',
data: {
funct: f,
roleName: r,
access: 'access'
},
OnFailure: "alert('error')",
success: function (data) {
$("#ajax-content").html(data);
loadAccess();
}
});
} //end loadBulkEdit
——对话框。保存时,调用 SaveRoleEntitlement 操作方法(视图上定义的 Ajax.BeginForm 选项
function loadAccess(xhr, status) {
$('#ajax-content').dialog({
modal: true,
width: 370,
title: $('#ajax-content legend').text(),
buttons: {
"Save": function () {
$('#ajax-content form').submit();
$(this).dialog('destroy').html('');
},
"Cancel": function () {
$(this).dialog('destroy').html('');
}
}
});
} //end popup
--控制器动作
public JsonResult SaveRoleEntitlement(RoleEntitlementEidtModel model)
{
try
{
string strPackageName = model.RoleName;
string strFebSecID = User.Identity.Name;
string strKeyValue = "";
string strFunction = model.Function;
string strAccessLevel = model.AccessLevel;
PatService.EditEntitlement(strFebSecID, strPackageName, strFunction, strAccessLevel, strKeyValue);
return Json(new { Error = string.Empty });
}
catch (Exception ex)
{
return Json(new { Error = ex.Message });
}
}
这很好用,只是我正在努力添加 1. 保存时的错误处理。如果有任何异常,我想向用户显示错误消息 2. 方法执行时进度条或某种“等待”消息。希望有人能帮助我。
谢谢。