Huma Ali
Huma Ali

Reputation: 1809

Use c# variable in Jquery

I have c# variable check that I want to use in my jquery if condition. But I am getting error

Uncaught ReferenceError: DGSCRM is not defined

where DGSCRM is the value present in my c# variable check.

@{
    string check = Model.ChangeAddress.ControllerName;
}
<script type=text/javascript>
    $(document).ready(function () 
    {
    if(@check == "DGSCRMAPI")
    {
        $('#logo').hide();
    }
});

</script>

Is it the right approach to mix c# and jquery code in views?

Upvotes: 2

Views: 6615

Answers (1)

BenG
BenG

Reputation: 15154

you need to wrap in "

if("@check" == "DGSCRMAPI")

Upvotes: 8

Related Questions