レコードの int ステータスを変更し、その変更に基づいてメールを送信したいのですが、ユーザーがステータスを変更する新しいページにリダイレクトする必要はありません。
列テンプレート ボタンを href の JsonResult アクションに関連付けようとしましたが、もちろんリダイレクトされます。
見た目からすると、カスタム コマンドが私の最善の策ですが、テーブルの編集が正常に機能するようになれば、電子メール以外のすべてを実行する既存のコードをできるだけ活用したいと考えています。
ステータス = 保留中/承認/却下
保留中がデフォルトであるため、グリッドでは承認と拒否のみがステータス変更のオプションとして表示されます。
コードを表示:-
{
field: 'Application',
template: '<a style=\'width: 80px\' class=\'btn btn-success btn-block\' href=\' + sitePath + 'Placement/_Approve?Id=#=Id#\'>Approve</button>',
width: 50
},
{
template: '<a style=\'width: 80px\' class=\'btn btn-warning btn-block\' href=\' + sitePath + 'Placement/_Decline?Id=#=Id#\'>Approve</button>',
width: 50
}
コントローラーのアクション
[HttpPost]
public JsonResult _Approve(int Id)
{
SBApplication sba = _db.SBApplications.Find(Id);
sba.PendingApprovedDeclined = 1;
Placement pl = _db.Placements.Find(sba.PlacementId);
if (pl.ApprovedCount == pl.PlacementSlots)
{
Session.Add("redirectedapprovelimit", "yes");
return Json(View(new { @Id = sba.PlacementId }));
}
int i = pl.ApprovedCount;
i++;
pl.ApprovedCount = i;
if (pl.PlacementSlots == pl.ApprovedCount)
{
pl.OpenClosedStatus = false;
}
if (ModelState.IsValid)
{
_db.Entry(pl).State = EntityState.Modified;
_db.Entry(sba).State = EntityState.Modified;
_db.SaveChanges();
//// Insert email to student stating that there application is approved
}
return Json(View(new { @Id = sba.PlacementId }), JsonRequestBehavior.AllowGet);
}