I'm looking to create a Bootstrap styled textbox, specifically, based on the exact example below:
<input class="span3" type="email" required>
Here's what I have so far:
@Html.TextBox("CustomerEmail", null, new { @class = "input-xlarge", type = "email", required = "required" })
However, required = "required"
clearly doesn't return just required
.
So, my question is, is there any way I can force it to return required like in the first example above when using Html.Textbox?
1. Required attribute: If you want to make an input mandatory to be entered by the user, you can use the required attribute. This attribute can be used with any input type such as email, URL, text, file, password, checkbox, radio, etc. This can help to make any input field mandatory.
Indicating form controls as required using asterisks (*) Asterisk (*) next to a form control's label usually indicates it as "required". Oftentimes, this asterisk's purpose is then explained somewhere else on the page.
The required attribute is a boolean attribute. When present, it specifies that a text area is required/must be filled out (in order to submit the form).
However, if one is handling mouse events, for instance, using JS, they can set the "required" attribute to "True" or "False" using the ". prop()" method. e.g.
i think you should use like this
@Html.TextBoxFor(model => model.Name, new { @class = "text", type = "email", required = "required" })
i think this will help you.
Try
new { required = string.Empty}
As an aside, according to the W3C docs, required
is a Boolean attribute, and I quote:
The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value. If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace.
Therefore
required required="required" required=""
all mean the same thing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With