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?
using
directive? (look at what the error message is telling you)using
directive forSystem.Text.RegularExpressions
?MVC
you can also addSystem.Text.RegularExpressions
namespace to yourWeb.config
file under theViews
folder