public static IHtmlString PasswordFor <TModel, TR>(this HtmlHelpers <TModel> html, Expression <Func <TModel, TR> > prop, object htmlAttributes) where TModel : class { var tag = HtmlTagBuilder.CreateInputElementFor(html, prop, HtmlInputType.Password, htmlAttributes); html.AppendValidationResults(tag); return(tag != null ? new NonEncodedHtmlString(tag.ToString()) : NonEncodedHtmlString.Empty); }
public void CreateInputElementForNonPropertyReturnsNull() { var person = new Person(); var helpers = new HtmlHelpers <Person>(null, null, person); var tag = HtmlTagBuilder.CreateInputElementFor(helpers, p => p.Grow(), HtmlInputType.Text, null); Assert.IsNull(tag); }
public void CreateInputElementStoresValueOfNonStringProperty() { var person = new Person() { FirstName = "Alice", Age = 42 }; var helpers = new HtmlHelpers <Person>(null, null, person); var tag = HtmlTagBuilder.CreateInputElementFor(helpers, p => p.Age, HtmlInputType.Text, null); Assert.AreEqual(Convert.ToString(person.Age), tag.Attribute("value").Value); }
public void CreateInputElementUsesPropertyNameAsAttrName() { var person = new Person() { FirstName = "Alice" }; var helpers = new HtmlHelpers <Person>(null, null, person); var tag = HtmlTagBuilder.CreateInputElementFor(helpers, p => p.FirstName, HtmlInputType.Text, null); Assert.AreEqual("firstname", tag.Attribute("name").Value, true); }
public void CreateInputElementDoesNotGenerateAttributeValueForNullProperty() { var person = new Person() { FirstName = null }; var helpers = new HtmlHelpers <Person>(null, null, person); var tag = HtmlTagBuilder.CreateInputElementFor(helpers, p => p.FirstName, HtmlInputType.Text, null); Assert.IsNull(tag.Attribute("value")); }
public void CreateInputPasswordElementNeverStoresPropertyValue() { var person = new Person() { FirstName = "Alice" }; var helpers = new HtmlHelpers <Person>(null, null, person); var tag = HtmlTagBuilder.CreateInputElementFor(helpers, p => p.FirstName, HtmlInputType.Password, null); Assert.IsNull(tag.Attribute("value")); }
public static IHtmlString TextBoxFor <TModel, TR>(this HtmlHelpers <TModel> html, Expression <Func <TModel, TR> > prop, object htmlAttributes) where TModel : class { var tag = HtmlTagBuilder.CreateInputElementFor(html, prop, HtmlInputType.Text, htmlAttributes); AppendValidationResults(html, tag); if (html.Model != null) { AppendOldValue(html, tag); } return(tag != null ? new NonEncodedHtmlString(tag.ToString()) : NonEncodedHtmlString.Empty); }
public static IHtmlString InputElementFor <TModel, TR>(this HtmlHelpers <TModel> html, Expression <Func <TModel, TR> > prop, object htmlAttributes) where TModel : class { var property = prop.AsPropertyInfo(); if (property == null) { return(NonEncodedHtmlString.Empty); } var inputType = GetInputTypeByProperty(property); var tag = inputType == HtmlInputType.Checkbox ? HtmlTagBuilder.CreateCheckBoxFor(html, prop, htmlAttributes) : HtmlTagBuilder.CreateInputElementFor(html, prop, inputType, htmlAttributes); return(tag != null ? new NonEncodedHtmlString(tag.ToString()) : NonEncodedHtmlString.Empty); }