开发者

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开发者_如何学Python: 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?


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


Wrap the javascript code within tag.

@{(if DEBUG)
    **<text>**
    $("#User").val("JDoe");
    $("#Password").val("secrect");
   **</text>**
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜