Created
February 3, 2016 17:03
-
-
Save avisser/964b9fc659cb76193df3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var toastTypes = new[] { "success", "error", "info", "warning" }; | |
foreach (var type in toastTypes) | |
{ | |
if (TempData.ContainsKey(type)) | |
{ | |
string message = (string)TempData[type]; | |
string title = null; | |
if (TempData.ContainsKey("title")) | |
{ | |
title = (string)TempData["title"]; | |
<script language="javascript"> | |
toastr['@type']('@message', '@title'); | |
</script> | |
} | |
else | |
{ | |
<script language="javascript"> | |
toastr['@type']('@message'); | |
</script> | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ToastrExtension | |
{ | |
public static void Success(this Controller controller, string message, string title = null) | |
{ | |
controller.TempData["success"] = message; | |
if (title != null) | |
{ | |
controller.TempData["title"] = title; | |
} | |
} | |
public static void Info(this Controller controller, string message, string title = null) | |
{ | |
controller.TempData["info"] = message; | |
if (title != null) | |
{ | |
controller.TempData["title"] = title; | |
} | |
} | |
public static void Warning(this Controller controller, string message, string title = null) | |
{ | |
controller.TempData["warning"] = message; | |
if (title != null) | |
{ | |
controller.TempData["title"] = title; | |
} | |
} | |
public static void Error(this Controller controller, string message, string title = null) | |
{ | |
controller.TempData["error"] = message; | |
if (title != null) | |
{ | |
controller.TempData["title"] = title; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment