0

I would like to show popup message if there is an error on the page but somehow jquery doesn't show anything.

 <script>
     $(document).ready(function () {
         if(@TempData["Error"].ToString() != null)
         {
             alert("Message 1");
         } else {
             alert("Message 2");
         }
    });
 </script>
Hassan
  • 910
  • 3
  • 15
  • 33
AliAzra
  • 757
  • 1
  • 6
  • 19

2 Answers2

0

ToString() is not the correct method name, the correct method name is toString()

Bear Nithi
  • 4,374
  • 15
  • 28
0

I fixed it with this way

    var val = '@Html.Raw((string)TempData["ErrorMessage"])';
    if(val != "")
    {
        alert(val);
    }
AliAzra
  • 757
  • 1
  • 6
  • 19