Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net MVC Razor - Custom javascript inside if block

How can I put javascript code inside if block.

@{
    #if DEBUG
    $("#User").val("JDoe");
    $("#Password").val("secrect");
    #endif
}

When I try above code I get this compiler error:

Compiler Error Message: CS1056: Unexpected character '$'

And if I change $ to jQuery:

Compiler Error Message: CS0103: The name 'jQuery' does not exist in the current context

In my opinion it's a bug in Razor parser. How can I workaround that?

like image 266
Zote Avatar asked Oct 20 '10 13:10

Zote


1 Answers

@{#if DEBUG}
    $("#User").val("JDoe");
    $("#Password").val("secrect");
@{#endif}
like image 181
takepara Avatar answered Oct 29 '22 02:10

takepara