-4

I am doing a Razor page. The following is the beginning of this cshtml file:

@{
    var year = Request.QueryString["year"];

    Match match = Regex.Match(year, @"^\d\d\d\d$", RegexOptions.IgnoreCase);
}

When loading the page, I got the following error:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0246: The type or namespace name 'Match' could not be found (are you missing a using directive or an assembly reference?)

Source Error:

How can I fix this error?

4
  • 1
    Are you missing a using directive? (look at what the error message is telling you) May 16, 2014 at 21:24
  • 2
    do you have a using directive for System.Text.RegularExpressions ? May 16, 2014 at 21:25
  • if this is MVC you can also add System.Text.RegularExpressions namespace to your Web.config file under the Views folder May 16, 2014 at 21:30
  • @Savanna: The accepted answer on that question isn't even in the ballpark. Despite the title, that question appears to be a highly-localized troubleshooting problem. May 16, 2014 at 21:38

2 Answers 2

8

Add this to the top of your file:

@using System.Text.RegularExpressions
0
1

Try adding @using System.Text.RegularExpressions ad the top of your template.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.