locked
to give if condition in javascript of the html RRS feed

  • Question

  • User-1355965324 posted

    I am calling the the following javascript in my chtml file. I want to call the function  ShowResultModalPopup and ShowErrorModalPopup only if the ViewBag.Result  and ViewBag.Error is not empty

    So I would like to change as follows

    If  @ViewBag.Result <> null 

    {

    ShowResultModalPopup('@ViewBag.Result');

    If  @ViewBag.Error<> null 

    {

    ShowErrorModalPopup('@ViewBag.Error');

    How can I give the if condition to check empty or not. Please help

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

    Friday, June 21, 2019 2:51 PM

Answers

  • User2103319870 posted

    polachan

    I want to call the function  ShowResultModalPopup and ShowErrorModalPopup only if the ViewBag.Result  and ViewBag.Error is not empty

    Try with below code

    $(document).ready(function () {
    	@if(ViewBag.Result !=null && ViewBag.Result !="")
    		{
    			<text>ShowResultModalPopup('@ViewBag.Result'); </text>
    		}else
    		{
    			<text>ShowResultModalPopup('ViewBag is empty'); </text>
    		}
      });
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 21, 2019 3:24 PM