【发布时间】:2012-04-30 12:25:28
【问题描述】:
我正在我的一个注册表单中实施验证码
在 Example.Cs 文件中我写了以下内容:
public static class CaptchaHelper
{
public static string Captcha(this HtmlHelper helper, string text)
{
string srcPath = System.Web.VirtualPathUtility.ToAbsolute("~/Handler1.ashx");
string htmlContent = string.Empty;
htmlContent += "<script type=\"text/javascript\">function __rc(){document.getElementById(\"" + text +
"\").src = \"../Handler1.ashx?query=\" + Math.random();}</script>";
htmlContent += string.Format("<img id=\"{0}\" src=\"{1}\" alt=\"Captcha Image\"/>", text, srcPath);
htmlContent += "<a href=\"#\" onclick=\"javascript:__rc();\">Reset</a>";
return htmlContent;
}
}
在 View (.cshtml) 中我写了以下内容:
@Html.Captcha("Sample")
代替图像显示脚本可以帮助任何人。
谢谢 巴努
【问题讨论】:
标签: asp.net-mvc-3 c#-4.0 razor entity-framework-4.1