private string StripSpecialChars(string inputString)
{
return (Regex.Replace(StripHTML(inputString), "[^A-Za-z0-9 ,]", ""));
}
Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts
Monday, November 29, 2010
How to strip non-alphanumeric chars from a string
The example below also leaves the space character and commas intact.
How to strip HTML tags out of a string
static string StripHTML(string inputString)
{
return Regex.Replace
(inputString, "<.*?>", string.Empty);
}
Saturday, September 18, 2010
How to create HTTP POST and GET methods with the same signature
When using Ajax Uploader (a very cool component) and MVC, I ran into a situation where I needed the same signature for the HTTP GET and HTTP POST controller actions. The compiler wouldn't let me use the same name. The ActionName attribute solved that problem.
[ActionName( "UploadArtwork" )]
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult UploadArtworkGet(string dataMyComponentUses)
{
...
return View( "UploadArtwork" );
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UploadArtwork(string dataMyComponentUses)
{
...
return View( "UploadArtwork" );
}
[ActionName( "UploadArtwork" )]
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult UploadArtworkGet(string dataMyComponentUses)
{
...
return View( "UploadArtwork" );
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UploadArtwork(string dataMyComponentUses)
{
...
return View( "UploadArtwork" );
}
How to return a pdf file in MVC (instead of preview by browser)
public ActionResult GetPDF(string filename)
{
return File(filename, "application/pdf" , Server.HtmlEncode(filename));
}
Subscribe to:
Posts (Atom)