ASP.NET MVC - Anti-spam HTML Helper


/ Published in: C#
Save to your folder(s)

Outputs the required form elements to use the ValidateAntiSpamAttribute


Copy this code and paste it in your HTML
  1. public static string AntiSpamConfirmation(this HtmlHelper helper)
  2. {
  3. TagBuilder label = new TagBuilder("label");
  4. label.Attributes.Add("for", "sixtimesnine");
  5. label.InnerHtml = "Are you a spam robot?";
  6.  
  7. TagBuilder p = new TagBuilder("p");
  8. p.InnerHtml = string.Format("{0}\n{1}\n{2}",
  9. label.ToString(TagRenderMode.Normal),
  10. helper.TextBox("sixtimesnine"),
  11. helper.Hidden("fourtytwo", "no"));
  12.  
  13. return p.ToString();
  14. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.