使用MVC 5 EditorFor从数字的输入类型中删除滑块/微调器

本文关键字:删除 类型 EditorFor MVC 数字 输入 使用 | 更新日期: 2023-09-27 18:29:54

我将Razor与MVC 5一起用于具有整数值的模型。如果我使用

@Html.EditorFor(model => model.WeekPrice, new { htmlAttributes = new { @class = "form-control" } })

我在文本框中出现了一个滑块/微调器;生成的HTML是:

<input type="number" ...

如果我使用@Html.TextboxFor(model或将数据类型更改为decimal,微调器将消失,HTML输入类型将更改为文本。

如何使用EditorFor并支持微调器?

使用MVC 5 EditorFor从数字的输入类型中删除滑块/微调器

我看不出你为什么不能使用TextBoxFor()来实现这个目的,因为本质上你试图将它显示为普通的TextBox控件,而不是数字上/下控件。无论如何,您可以使用CSS来实现这一点。取自CSS技巧:关闭数字输入微调器

input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
  -webkit-appearance: none; 
  margin: 0; 
}