Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating numeric up down or value control using razor

I am using asp.net mvc4 razor, and I would like to know if there is some control in razor to allow enter numeric and positive integers values. Is there any?

like image 975
Ralph Avatar asked Dec 22 '25 05:12

Ralph


2 Answers

You can achieve the same in MVC by using the htmlAttributes parameter of HtmlHelper's EditorFor():

  @Html.EditorFor(model => model.CreditCardExpirationMonth, new { htmlAttributes = new { type="number", min="1", max="12", @class = "form-control" } })
like image 52
Rupa Mistry Avatar answered Dec 24 '25 09:12

Rupa Mistry


The only "built in" thing you can do is use HTML5 input in your form:

<input type="number" min="0" />

Or

<input type="text" pattern="\d*" /> 

For the list of all input type number attributes check out this link http://www.w3.org/TR/html-markup/input.number.html

like image 26
Davor Zlotrg Avatar answered Dec 24 '25 09:12

Davor Zlotrg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!