Can't reference Regex in string extension method
I have run into very strange problem: I have made extension method for string like this:
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.RegularExpre开发者_开发问答ssions.Regex("[^a-zA-Z0-9 -]");
encodedUrl = rgx.Replace(encodedUrl, "-");
return encodedUrl;
}
}
}
And problem that durning runstime I get error: CS0246: The type or namespace name 'Regex' could not be found (are you missing a using directive or an assembly reference?)
Im not missing using directive. Nor do I missing Assembly (I can use Regex withing controller for example). I have put my extension method into App_Code, but doubt it have any connection,
Move the cs file to another directory (out of App_Code folder) put it on the root of the project.
Check this article
精彩评论