MvcCaptcha 示例 — 自定义验证码文本
View:
@using Webdiyer.WebControls.Mvc @using (Html.BeginForm()) { <div>@ViewData["Message"] </div> @Html.ValidationSummary() @Html.MvcCaptcha(new MvcCaptchaOptions { ValidationInputBoxId = "captchaTextBox", CaptchaImageContainerId = "captchaImage", TextChars = "上中下左右大小多少人口手山石田土禾木水火", ReloadLinkText = "看不清?换一张" }) <span id="captchaImage"></span> <br /> <div>请输入上边图片中的文字:</div> <input type="text" name="captchaTextBox" id="captchaTextBox" /> <input type="submit" value="提交" /> }
Controller:
public ActionResult TextChars() { return View(); } [HttpPost, ValidateMvcCaptcha("captchaTextBox")] public ActionResult TextChars(FormCollection values) { if (ModelState.IsValid) { //在这里执行表单提交成功后的操作 ViewData["Message"] = "<span class=\"success\">验证通过,表单提交成功!</span>"; } else ViewData["Message"] = "<span class=\"error\">验证未通过,表单提交失败!</span>"; return View(); }
该示例演示如何为MvcCaptcha验证码控件应用自定义验证码文本