123456789101112131415161718192021222324252627282930 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Web.Mvc;
- using System.Linq.Expressions;
- namespace Bowin.Web.Controls.Mvc
- {
- public static class VerfyCodeExtensions
- {
- public static MvcHtmlString VerfyCodeFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, string url)
- {
- if (expression == null)
- {
- throw new ArgumentNullException("expression");
- }
- ModelMetadata modelMetadata = ModelMetadata.FromLambdaExpression<TModel, TProperty>(expression, htmlHelper.ViewData);
- string fullHtmlFieldName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(ExpressionHelper.GetExpressionText(expression));
- StringBuilder sb = new StringBuilder();
- sb.AppendFormat("<input type=\"text\" size=\"8\" name=\"{0}\" ", fullHtmlFieldName);
- sb.Append(" style=\"float: left; margin-right: 4px;border: 1px solid #cbcbcb;\" tabIndex=\"0\" placeholder=\"请输入右侧验证码\" />");
- sb.AppendFormat("<img style=\"cursor: hand;\" id=\"vcodeimg\" title=\"点击刷新验证码\" onclick=\"this.src='{0}?' + Math.random()\"", url);
- sb.AppendFormat(" src=\"{0}\" alt=\"\" />", url);
- return MvcHtmlString.Create(sb.ToString());
- }
- }
- }
|