如何在mvc4的cshtml视图页面的html.textboxfor中设置数字范围验证? [英] How to set a number range validation in html.textboxfor in cshtml view page in mvc4?

查看:230
本文介绍了如何在mvc4的cshtml视图页面的html.textboxfor中设置数字范围验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

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

如何在mvc4的cshtml视图页面的@html.textboxfor中将数字限制设置为0到100?

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

推荐答案

您可以使用Range属性将输入限制为0到100.您可以将此属性应用于正在使用的模型的(target)属性视图.

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; }

这篇关于如何在mvc4的cshtml视图页面的html.textboxfor中设置数字范围验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆