Razor property without html value

My text fields look something like this

@Html.TextBox("Something", "", new { type = "text", min = 1, max = 60, data_validation_integer_regex = @ValidationPatterns.Integer, data_validation_integer_message = @ValidationPatterns.IntegerMessage, data_bind = "value: observables.Something" }) 

What is displayed as

  <input data-bind="value: observables.Something" data-validation-integer-message="Some message" data-validation-integer-regex="^[1-9]\d*$" id="Something" max="60" min="1" name="Something" type="text" value=""> 

Validation library we use jqBootstrapValidation

I would like to make some of my fields and a way to do this using this library, I need to add a tag to the input field, for example:

<input id="Something" ... required >

Razor does not allow me to do this, although it seems that all the parameters in this format

property="something" or property=100

is my only option returning to the standard html markup if I want to make my fields mandatory?

+4
source share
1 answer

If you use a property with an empty string ( required="" ), then Razor will display it as a useless attribute. I.e

 @Html.TextBox("name", "value", new { attr="something", required="" }) 

Refers to:

 <input type='text' name='name' id='id' value='value' attr='something' required /> 
+4
source

Source: https://habr.com/ru/post/1446154/


All Articles