The razor engine processes the @ symbol in Js.

Source: Internet
Author: User

A simple statement:
If (! /^ \ W + [\. \ +]? \ W + @ \ W + \. \ W + $/. test (s) Alert ("fail ");
An error occurred while running because @ appears in the regular expression @
So I changed the regular expression to/^ \ W + [\. \ +]? \ W + @ \ W + \. \ W + $/
In Razor's syntax, @ outputs a @ symbol, but the result still reports the same error,
However, I wrote the above to the blank area of the page, but it can be normally output and no error is reported. It can be seen that the razor syntax is written in <SCRIPT> and there is a problem, which cannot be solved after repeated attempts. Finally, the detour is solved:
VaR v = @{
@:/^ \ W + [\. \ +]? \ W + @ \ W + \. \ W + $/
}
If (! V. test (s) Alert ("fail ");

Is there any awkward solution? I mean, if you must write it on the cshtml page, throwing the JS file to the outside will certainly avoid this situation. But what I want to know now is how to solve this problem under the razor syntax, instead of bypassing it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.