【发布时间】:2011-06-11 01:21:26
【问题描述】:
我遇到了一个很奇怪的问题: 我为这样的字符串做了扩展方法:
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 指令或程序集引用?)
我没有错过 using 指令。我也没有错过大会(例如,我可以使用 Regex withing 控制器)。 我已将我的扩展方法放入 App_Code,但怀疑它是否有任何联系,
【问题讨论】:
-
您是否尝试过清理您的解决方案并强制重建?
-
并不是说这完全解决了你的问题,但是如果你在网址上使用
.ToLower(),为什么你的正则表达式中有A-Z? -
尝试将
using移动到namespace内部