/// <summary> /// 为 <see cref="HtmlHelper"/> 对象扩展 span 元素。 /// </summary> /// <typeparam name="TModel">数据模型类型。</typeparam> /// <typeparam name="TProperty">绑定的属性的类型。</typeparam> /// <param name="htmlHelper"></param> /// <param name="expression">指定绑定属性的表达式。</param> /// <returns></returns> public static HtmlHelper <TModel> Label <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression) { var metadata = new ModelPropertyBinder(expression); var propertyName = metadata.PropertyName; htmlHelper.ResetBuilder("SPAN", "lbl" + propertyName, propertyName); htmlHelper.Builder.TagClosed = true; return(htmlHelper); }
/// <summary> /// 为 <see cref="HtmlHelper"/> 对象扩展 input 元素。 /// </summary> /// <typeparam name="TModel">数据模型类型。</typeparam> /// <typeparam name="TProperty">绑定的属性的类型。</typeparam> /// <param name="htmlHelper"></param> /// <param name="expression">指定绑定属性的表达式。</param> /// <returns></returns> public static HtmlHelper <TModel> Input <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression) { var metadata = new ModelPropertyBinder(expression); var propertyName = metadata.PropertyName; htmlHelper.ResetBuilder("INPUT", "txt" + propertyName, propertyName); htmlHelper.AddAttribute("type", "text"); return(htmlHelper); }
public static HtmlHelper <TModel> RadioGroup <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, Type enumType, RadioGroupSettings settings = null) { var metadata = new ModelPropertyBinder(expression); var propertyName = metadata.PropertyName; htmlHelper.ResetBuilder("DIV", "rgp" + propertyName, propertyName); htmlHelper.AddClass("radio-group"); htmlHelper.AddStyle("width", "160px"); htmlHelper.Builder.SetInnerHtml(BuildRadioOptions(propertyName, enumType, settings)); return(htmlHelper); }
/// <summary> /// 为 <see cref="HtmlHelper"/> 对象扩展 checkbox 元素。 /// </summary> /// <typeparam name="TModel">数据模型类型。</typeparam> /// <typeparam name="TProperty">绑定的属性的类型。</typeparam> /// <param name="htmlHelper"></param> /// <param name="expression">指定绑定属性的表达式。</param> /// <param name="checked">默认是否选中。</param> /// <returns></returns> public static HtmlHelper <TModel> CheckBox <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, bool @checked = false) { var metadata = new ModelPropertyBinder(expression); var propertyName = metadata.PropertyName; htmlHelper.ResetBuilder("INPUT", "chk" + propertyName, propertyName); htmlHelper.AddAttribute("type", "checkbox"); if (@checked) { htmlHelper.AddAttribute("checked", "checked"); } return(htmlHelper); }