Мне нравится понимать, почему мое предупреждающее сообщение не отображается, я создал общий класс, controller и cshtml.
Чего-то не хватает в контроллере?
Общий класс
SettingController controller = new SettingController();
controller.ShowWarning("Warning on page");
Класс контроллера
public ActionResult ShowWarning(string message)
{
TempData["Warning"] = message;
// returning view counts as providing response
return View();
}
Alert.cshtml
<script type="text/javascript">
$(document).ready(function() {
@foreach (var key in Enum.GetNames(typeof(Messages)))
{
if (TempData.ContainsKey(key) || Session[key] != null)
{
var message = TempData[key] ?? Session[key];
var type = "success";
if (key == Messages.Warning.ToString())
{
type = "notice";
} else if (key == Messages.Danger.ToString())
{
type = "error";
}
<text>
new PNotify({
title: false,
text: '@Html.Raw(message.ToString().Replace("'", "\'").Replace("\r\n", "<br/>"))',
type: '@type',
styling: 'bootstrap3'
});
</text>
}
}
});
</script>