locked
the name doesnot exist in the current context RRS feed

  • Question

  • User-1355965324 posted

    When I call the function ShowResultModalPopup  from inside the if condition , the error message ' The name ShowResultModalPopup doesnot exist in the current context error is coming.  If I am calling  without if condition there is no error will be coming. How can I  call the function only if ViewBag.Result is not null or not empty. The function I have declared in site.js

    <script type="text/javascript">
        $(document).ready(function () {
    @if(ViewBag.Result !=null && ViewBag.Result !="")
            {
                ShowResultModalPopup('@ViewBag.Result');
            }
    
            @if (@ViewBag.Error != null && @ViewBag.Error != "")
            {
                ShowResultModalPopup('@ViewBag.Result');
            }
    
     
    })

     

    in Site.Js
    
    function ShowResultModalPopup(message) {
        if (message !== '') {
            $('#divMessage').html(message);
            $('#ResultModal').modal('show');
        }
    }
    
    function ShowErrorModalPopup(message) {
        if (message !== '') {
            $('#divErrorMessage').html(message);
            $('#ErrorModal').modal('show');
        }
    }



     

    Saturday, June 22, 2019 7:06 AM

Answers

  • User-474980206 posted
    The razor syntax thinks ShowResultModalPopup is a c# call, not text to be rendered. Use @: or <text> syntax to let razor know it’s html text

    <text>ShowResultModalPopup(‘@ViewBag.Result’);</text>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, June 22, 2019 4:44 PM