【问题标题】:How do I make my text box only take numbers?如何让我的文本框只接受数字?
【发布时间】:2015-12-30 09:12:09
【问题描述】:

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

HTML代码:

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

提前致谢。

【问题讨论】:

  • @Html.TextBox("SearchString2", null, new { @type="number" }) - 你使用了错误的重载
  • 您应该将此作为答案发布,我会标记它:) @StephenMuecke

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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-28
    • 2011-06-15
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    • 2013-12-05
    • 1970-01-01
    • 2010-10-21
    相关资源
    最近更新 更多