无法在字符串扩展方法中引用正则表达式



我遇到了一个非常奇怪的问题:我为字符串做了这样的扩展方法:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Vaniv.Mvc
{
    public static class StringHelpers
    {
        public static string ToSeoUrl(this string url)
        {
            // make the url lowercase
            string encodedUrl = (url ?? "").ToLower();
            System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex("[^a-zA-Z0-9 -]");
            encodedUrl = rgx.Replace(encodedUrl, "-");
            return encodedUrl;
        }
    }
}

在运行过程中我遇到的问题是:CS0246:未能找到类型或命名空间名称"Regex"(是否缺少using指令或程序集引用?)

我没有错过使用指令。我也没有错过Assembly(例如,我可以在控制器中使用Regex)。我已经将我的扩展方法放入App_Code中,但怀疑它是否有任何连接,

将cs文件移动到另一个目录(App_Code文件夹外),并将其放在项目的根目录上。

查看这篇文章

最新更新