保存数据后来自Controller的警报消息 [英] Alert Message from Controller after Saving Data

查看:73
本文介绍了保存数据后来自Controller的警报消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





填写Gmail注册表单,我想在保存数据后显示警告信息框,我想这可以通过Controller完成,所以请问任何想法?

Hi,

Filling a form like Gmail registration, I want to display alert message box after saving the data, I think this can be done from Controller, so please any idea?

推荐答案

您好,在视图中添加此代码

Hi, Add this code in view
@{
    if (TempData["message"] != null) {
    <script type="text/javascript">
        alert(@Html.Raw(Json.Encode(TempData["message"])));
    </script>
}
    }










[HttpPost]
        public ActionResult Submit()
        {
            if (ModelState.IsValid)
            {
               // Do your stuff
            TempData["message"] = "Your Message";
            }


            return View("ViewName");
        }


插入数据到数据库后的显示方式 - 警告 - 消息[ ^ ]



how-to-display-alert-message-in-控制器 [ ^ ]


您好,



您可以使用Ajax.BeginForm。它为您提供了AjaxOptions。使用它,您可以在控制器操作成功/失败后触发javascript函数。



这是一个例子。



@Ajax.BeginForm(ActionName,ControllerName,null,new AjaxOptions(){OnSuccess =javascript:alert('Login Successfully!');},new {})





--SDK
Hi,

You can use Ajax.BeginForm. Which provides you AjaxOptions. Using that, you can fire javascript function after success/failure of your controller action.

Here is one example.

@Ajax.BeginForm("ActionName","ControllerName",null,new AjaxOptions(){OnSuccess = "javascript:alert('Login Successfully!');"},new{})


--SDK


这篇关于保存数据后来自Controller的警报消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆