这里是 MVC 新手。
我想在 Controller 操作(更新记录)之前获得用户确认
我的代码:
[HttpPost]
public ActionResult JobHandlerUpdate(int jobScheduleId, JobHandlerList jobHandlerList)
{
var updateJobHander = new MainJobHandler();
var item = updateJobHander.GetById(jobScheduleId);
if (ModelState.IsValid)
{
List<string> days = jobHandlerList.JobProcessDayOfWeek.Split(',').ToList();
updateJobHander.Update(item, days);
if(jobHandlerList.MaxInstances == 0)
{
// here I need to prompt user if maxInstances entered is Zero-
Job will be disabled want to processs (Y/N) if yes update
else do nothing or redirect to edit screen
}
return RedirectToAction("JobHandler");
}
return View(item);
}
我需要使用 javascript 警报吗? 或者有什么好的办法吗?
最佳答案
您可能可以使用 onClick 事件处理程序:
<input type="submit" onclick="return confirm('Are you sure you wish to submit?');" />
你只能做客户端提示,因为你的Controller代码是在服务器上执行的,客户端当然无法访问。
关于c# - MVC + 我如何在 Controller 操作之前提醒提示用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4330529/