![](/img/trans.png)
[英]asp.net mvc 4 javascript inside razor block throws error
[英]Asp.net MVC Razor - Custom javascript inside if block
如果阻止我怎么能把javascript代碼放在里面。
@{
#if DEBUG
$("#User").val("JDoe");
$("#Password").val("secrect");
#endif
}
當我嘗試上面的代碼時,我得到這個編譯錯誤:
Compiler Error Message: CS1056: Unexpected character '$'
如果我將$更改為jQuery:
Compiler Error Message: CS0103: The name 'jQuery' does not exist in the current context
在我看來,這是Razor解析器中的一個錯誤。 我該如何解決這個問題?
@{#if DEBUG}
$("#User").val("JDoe");
$("#Password").val("secrect");
@{#endif}
將javascript代碼包裝在代碼中。
@{(if DEBUG)
**<text>**
$("#User").val("JDoe");
$("#Password").val("secrect");
**</text>**
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.