1: public static string CaptchaTextBox(this HtmlHelper helper, string name)
2: {
3: return helper.CaptchaTextBox(name, null);
4: }
5: public static string CaptchaTextBox(this HtmlHelper helper, string name,
6: Object htmlAttributes)
7: {
8: return helper.CaptchaTextBox(name,
9: ((IDictionary<string, object>)new RouteValueDictionary(htmlAttributes)));
10: }
11: public static string CaptchaTextBox(this HtmlHelper helper, string name,
12: IDictionary<String, Object> htmlAttributes)
13: {
14: ModelState state;
15: TagBuilder builder = new TagBuilder("input");
16: builder.MergeAttributes<string, object>(htmlAttributes);
17: builder.MergeAttribute("type", "text");
18: builder.MergeAttribute("name", name);
19: builder.MergeAttribute("id", name);
20: builder.MergeAttribute("value", "");
21: builder.MergeAttribute("maxlength",
22: ManagedFusion.Web.Controls.CaptchaImage.TextLength.ToString());
23: builder.MergeAttribute("autocomplete", "off");
24:
25: if (helper.ViewData.ModelState.TryGetValue(name, out state)
26: && (state.Errors.Count > 0))
27: {
28: builder.AddCssClass("input-validation-error");
29: }
30: return builder.ToString(TagRenderMode.SelfClosing);
31: }