public static MvcHtmlString ToggleSwitchFor <TModel>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, bool> > expression, bool isReadOnly, object htmlAttributes = null) { //<label> // <input type="checkbox" class="toggle-switch" name="something" id="something" /> // <input type="hidden" name="something" value="false" /> // <span class="switch"></span> //</label> var indexedAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); if (!indexedAttributes.Any()) { indexedAttributes.Add("class", "toggle-switch"); } if (isReadOnly) { AttributeMaker.AddDisabled(indexedAttributes); } StringBuilder result = new StringBuilder(); var checkbox = htmlHelper.CheckBoxFor(expression, indexedAttributes); result.Append("<label class='toggle-switch-label'>"); result.Append(checkbox); result.Append("<span class=\"switch\"></span>"); result.Append("</label>"); return(MvcHtmlString.Create(result.ToString())); }
public static MvcHtmlString ButtonForAddEditSelectItem <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, string URLAction, bool isReadOnly, object htmlAttributes = null) { TagBuilder aTag = new TagBuilder("a"); TagBuilder result = new TagBuilder("button"); var fieldName = ExpressionHelper.GetExpressionText(expression); var attrs = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); if (isReadOnly) { AttributeMaker.AddReadOnly(attrs); AttributeMaker.AddDisabled(attrs); } else { aTag.Attributes.Add("href", URLAction); aTag.Attributes.Add("data-origin", fieldName.Replace('.', '_')); result = aTag; } foreach (var attr in attrs) { result.Attributes.Add(attr.Key, attr.Value.ToString()); } return(MvcHtmlString.Create(result.ToString())); }
public static MvcHtmlString TextAreaReadOnlyFor <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, bool isReadOnly, object htmlAttributes = null) { var attrs = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); if (isReadOnly) { AttributeMaker.AddReadOnly(attrs); } return(helper.TextAreaFor(expression, attrs)); }
public static MvcHtmlString TextBoxForDateTime <TModel>(this HtmlHelper <TModel> helper, Expression <Func <TModel, DateTime> > expression, bool isReadOnly, object htmlAttributes = null) { var attrs = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); if (isReadOnly) { AttributeMaker.AddReadOnly(attrs); } return(helper.TextBoxFor(expression, "{0:" + CommonResources.DateTimeBinder_DateTimeFormat + "}", attrs)); }
public static MvcHtmlString DropDownListReadOnlyFor <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, IEnumerable <SelectListItem> selectList, bool isReadOnly, object htmlAttributes = null) { var attrs = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); if (isReadOnly) { AttributeMaker.AddReadOnly(attrs); AttributeMaker.AddDisabled(attrs); } return(helper.DropDownListFor(expression, selectList, attrs)); }
public static MvcHtmlString RadioButtonReadOnlyFor <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, bool isReadOnly, object value, object htmlAttributes = null) { var indexedAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); if (isReadOnly) { AttributeMaker.AddDisabled(indexedAttributes); AttributeMaker.AddReadOnly(indexedAttributes); } StringBuilder result = new StringBuilder(); var radiobutton = helper.RadioButtonFor(expression, value, indexedAttributes); result.Append(radiobutton); return(MvcHtmlString.Create(result.ToString())); }