C # code

try { //бла бла } catch (Exception) { ViewBag.Error = "Возникли проблемы при отправке вопроса!"; } 

HTML button

 <button class="btn btn-primary" type="submit" onclick="Notification"><i class="fa fa-envelope" aria-hidden="true"></i> Отправить</button> 

Create notification script

 <script> function Notification() { if (@ViewBag.Error != null) { $.notify("Вопрос успешно отправлен",{ globalPosition: "top center", // Распологается поцентру className: "success" // Успешное выполнение }); } else { $.notify("Возникли проблемы при отправке вопроса!",{ globalPosition: "top center", // Распологается поцентру className: "error" // Успешное выполнение }); } } </script> 
  • onclick="Notification" => onclick="Notification()" - Rostyslav Kuzmovych
  • no, this is not the error @Rostyslav_Kuzmovych - Ivan Ivan
  • try to remove type="submit" and see what happens - Rostyslav Kuzmovych
  • no, it doesn’t work @Rostyslav_Kuzmovych - Ivan Ivan
  • Something like this was stackoverflow.com/questions/6935828/… Maybe you need to write @if (ViewBag.Error! = Null) - coder675

1 answer 1

Works :

 function Notification() { $.notify("Вопрос успешно отправлен", { globalPosition: "top center", // Распологается поцентру className: "success" // Успешное выполнение }); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/notify/0.4.2/notify.js"></script> <button class="btn btn-primary" type="submit" onclick="Notification()"><i class="fa fa-envelope" aria-hidden="true"></i> Отправить</button> 

Does not work :

 function Notification() { $.notify("Вопрос успешно отправлен", { globalPosition: "top center", // Распологается поцентру className: "success" // Успешное выполнение }); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/notify/0.4.2/notify.js"></script> <button class="btn btn-primary" type="submit" onclick="Notification"><i class="fa fa-envelope" aria-hidden="true"></i> Отправить</button> 

  • I have already set the brackets, but everything does not work early with if - Ivan Ivan
  • look at what script you have generated and see if there are any errors in the conosol? - Rostyslav Kuzmovych
  • Contact: 102 Uncaught SyntaxError: Unexpected identifier dl.metabar.ru/static/storage/js/storage.min.js?version=201802221518:1 Uncaught DOMException: Failed to execute 'setItem' on 'Storage': Setting the value of ' domains' exceeded the quota. at HTMLScriptElement.a.onload ( dl.metabar.ru/static/storage/js/… ) - Ivan Ivan
  • Apparently the error is not in the notification, it is somewhere here: dl.metabar.ru/static/storage/js/storage.min.js - Rostyslav Kuzmovych
  • wrong syntax in @ ViewBag.Error string - Ivan Ivan