在控制器方法完成后在toastr中显示消息 [英] Display message in a toastr after controller method finish

查看:104
本文介绍了在控制器方法完成后在toastr中显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有控制器方法上传图像文件,使用jQuery AJAX,从< input> 类型文件,该方法返回:

i have controller method that upload image file, not using jQuery AJAX, from <input> type "file", the method returns:

Return Redirect(Request.UrlReferrer.PathAndQuery)

因为我希望在提交点击后保持相同的视图。

Because i want to stay in the same view after the submit click.

我想在成功图像后显示上传, toastr.success

I want to show after the success image upload, toastr.success.

我怎么做?

推荐答案

在http post action方法中,成功上传后,设置一个条目到TempData字典并在下一个视图中读取它,该视图由Redirect方法加载并显示toastr信息。

In your http post action method, after successful upload, set an entry to TempData dictionary and read it in the next view which is loaded by the Redirect method and display the toastr message.

TempData["Msg"] = "Uploaded successfully";
return Redirect(Request.UrlReferrer.PathAndQuery);

在您的视图中

<script>
  $(function(){
     var msg = "@(TempData["Msg"] as string)";
     if (msg !== "") {
         toastr.success(msg);
     }
  });
</script>

这篇关于在控制器方法完成后在toastr中显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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