简体   繁体   中英

How do I make my text box only take numbers?

I want to set it so that you can only input values in the textbox, plain and simple. But the picture shows the result I get. Any idea what the problem is? I had one text box set up like this a few months back so I know that something in the lines if this should work.

代码结果图

Html code:

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

Thanks in advance.

Your using the wrong overload of Html.TextBox() ( this one ) where the second parameter is the value to display. You need to use this one

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM