How to set a number range validation in html.textb

2019-06-21 08:16发布

问题:

Code:

@Html.TextBoxFor(x => x.PercentNos, new {@class = "percentage-numbers"})

How to set the numbers limit 0 to 100 in @html.textboxfor in cshtml view page in mvc4?

回答1:

You can use the Range attribute to limit the input from 0 to 100. You apply this attribute to the (target) property of the model you are using in your view.

[Range(0,100)]
public int PercentNos { get; set; }