I need to put the value of a TextBox
required like this :
<td>@Html.TextBoxFor(m =>(m.Code), new { @required = "required"})</td>
It works. But if i set a default value to the TextBox
<td>@Html.TextBoxFor(m =>(m.Code), new { @Value = @Model.Code, @required = "required"})</td>
An empty value becomes accepted despite the generation of this Html code
<td><input id="Code" name="Code" required="required" type="text" value="fff "></td>
Show activity on this post. TextBoxFor: It will render like text input html element corresponding to specified expression. In simple word it will always render like an input textbox irrespective datatype of the property which is getting bind with the control. EditorFor: This control is bit smart.
The TextBoxes can be made ReadOnly by setting the HTML ReadOnly attribute using the HtmlAttributes parameter in Html. TextBox and Html. TextBoxFor helper functions.
You can make the input 'read only' by using 'readonly'. This will let the data be POSTED back, but the user cannot edit the information in the traditional fashion. Keep in mind that people can use a tool like Firebug or Dragonfly to edit the data and post it back.
TextBoxFor<TModel,TProperty>(HtmlHelper<TModel>, Expression<Func<TModel,TProperty>>, Object) Returns a text input element for each property in the object that is represented by the specified expression, using the specified HTML attributes.
I don't know why but when i delete the space between =
and @
<td>@Html.TextBoxFor(m =>(m.Code), new { @Value [email protected], @required = "required"})</td>
it works
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