public static MvcHtmlString DateBoxFor <TModel, TProperty>( this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, DateOptions options ) { return(DateBoxFor(helper, expression, options, null)); }
public static MvcHtmlString DateBoxFor <TModel, TProperty>( this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, DateOptions options, object htmlAttributes ) { IDictionary <string, object> attrs = SetAttributes(options, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); return(helper.TextBoxFor(expression, attrs)); }
private static IDictionary <string, object> SetAttributes(DateOptions options, IDictionary <string, object> attrs) { if (attrs == null) { attrs = new Dictionary <string, object>(); } attrs.Add("onfocus", "WdatePicker(" + GetDateBoxOptions(options) + ");"); attrs.Add("autoComplete", "off"); ClientHelper.AddAttr(attrs, "class", "Wdate"); return(attrs); }
public static MvcHtmlString DateBox( this HtmlHelper helper, string name, string value, DateOptions options, object htmlAttributes ) { IDictionary <string, object> attrs = SetAttributes(options, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); return(helper.TextBox(name, value, attrs)); }
/// <summary> /// 获取日期框的客户端的参数配置 /// </summary> /// <param name="options"></param> /// <returns></returns> private static string GetDateBoxOptions(DateOptions options) { if (options == null) { options = new DateOptions(); } StringBuilder sb = new StringBuilder(); sb.Append("{"); sb.AppendFormat("el:this,dateFmt:'{0}'", options.DateFmt); if (options.DoubleCalendar) { sb.Append(",doubleCalendar:true"); } if (!string.IsNullOrEmpty(options.MinDate) || !string.IsNullOrEmpty(options.MinDateClientID)) { if (!string.IsNullOrEmpty(options.MinDateClientID)) { sb.Append(",minDate:'#F{$dp.$D(\\'" + options.MinDateClientID + "\\');}'"); } else { sb.AppendFormat(",minDate:'{0}'", options.MinDate); } } if (!string.IsNullOrEmpty(options.MaxDate) || !string.IsNullOrEmpty(options.MaxDateClientID)) { if (!string.IsNullOrEmpty(options.MaxDateClientID)) { sb.Append(",maxDate:'#F{$dp.$D(\\'" + options.MaxDateClientID + "\\');}'"); } else { sb.AppendFormat(",maxDate:'{0}'", options.MaxDate); } } if (!string.IsNullOrEmpty(options.StartDate)) { sb.AppendFormat(",startDate:'{0}'", options.StartDate); } if (options.IsShowWeek) { sb.Append(",isShowWeek:true"); } if (!options.IsShowClear) { sb.Append(",isShowClear:true"); } if (options.DisabledDates != null && options.DisabledDates.Length > 0) { sb.Append(",disabledDates:["); for (int i = 0; i < options.DisabledDates.Length; i++) { sb.AppendFormat("'{0}'", options.DisabledDates[i]); if (i < options.DisabledDates.Length - 1) { sb.Append(","); } } sb.Append("]"); } sb.Append("}"); return(sb.ToString()); }
public static MvcHtmlString DateBox(this HtmlHelper helper, string name, string value, DateOptions options) { return(DateBox(helper, name, value, options, null)); }