Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable spin buttons in razor view of asp.net?

Tags:

asp.net

In model class column name is public int? CTScore { get; set; } and in Razor view I want to use this as @Html.EditorFor(model => model.CTScore).

It is showing as editor box along with Up/Down arrow spin buttons, but I need not show those spin buttons. How to do?

Any help is appreciated.

like image 314
Dev Avatar asked Mar 20 '23 11:03

Dev


2 Answers

It sounds like Razor is adding type="number" to your input field, which causes modern browsers to show the spin buttons. If you want to disable this, and use type="text" instead, you can add a DataType attribute to your property:

[DataType(DataType.Text)]
public int? CTScore { get; set; }
like image 98
Joe White Avatar answered May 10 '23 00:05

Joe White


The following line is what you need.

@Html.EditorFor(model => model.CTScore, new { htmlAttributes = new { @type="text" } })
like image 45
fcdimitr Avatar answered May 09 '23 22:05

fcdimitr