如何让我的文本框只取数字?

时间:2015-10-02 07:29:29

标签: html asp.net-mvc asp.net-mvc-4

我想设置它,以便您只能在文本框中输入简单明了的值。但是图片显示了我得到的结果。知道问题是什么吗?几个月前我有一个像这样设置的文本框,所以我知道如果这应该有效的话就行了。

Picture of the result of the code

Html代码:

if (Roles.IsUserInRole(WebSecurity.CurrentUserName, "Admin"))
{
    @:<p><b>Customer ID:</b> @Html.TextBox("SearchString2", new {@type="number"})</p>
}

提前致谢。

1 个答案:

答案 0 :(得分:3)

您使用Html.TextBox()this one)的错误重载,其中第二个参数是要显示的值。您需要使用this one

@Html.TextBox("SearchString2", null, new { @type="number" })
相关问题