Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用MVC 5 EditorFor从数字的输入类型中删除滑块/微调器_C#_Asp.net Mvc_Razor - Fatal编程技术网

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

C# 使用MVC 5 EditorFor从数字的输入类型中删除滑块/微调器,c#,asp.net-mvc,razor,C#,Asp.net Mvc,Razor,我将Razor与MVC5一起用于一个具有整数值的模型。如果我使用 @Html.EditorFor(model => model.WeekPrice, new { htmlAttributes = new { @class = "form-control" } }) 我得到一个滑块/微调器出现在文本框中;生成的HTML是: <input type="number" ... 我看不出有任何理由不能为此使用TextBoxFor(),因为本质上,您试图将其显示为普通TextBox控件,而

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

@Html.EditorFor(model => model.WeekPrice, new { htmlAttributes = new { @class = "form-control" } })
我得到一个滑块/微调器出现在文本框中;生成的HTML是:

<input type="number" ...

我看不出有任何理由不能为此使用
TextBoxFor()
,因为本质上,您试图将其显示为普通
TextBox
控件,而不是数字上下控件。无论如何,您可以使用CSS来实现这一点。取自


使用
TextBoxFor()
有什么问题吗?
EditorFor()
方法专门设计用于基于属性类型(或基于
[DataType]
属性)生成
type
属性,因此它使用浏览器HTML5 inputsSimple,我更喜欢样式。我也想了解如何做到这一点。什么风格?(您可以使用
TextboxFor()
实现完全相同的功能)。如果您确实想使用
EditorFor()
方法,可以尝试
new{htmlAttributes=new{@class=“form control”,type=“text”}
但这只是额外的代码文本框的形状有所不同。但是,如果你在答案中添加评论,我很乐意接受。我真的不知道为什么你不直接使用
@Html.TextBoxFor(m=>m.WeekPrice,new{@class=“form control”}
,它将生成标准的
type=“text”
input。请注意,
type=“number”
将使用浏览器实现的数字输入,不同浏览器的数字输入外观会有所不同
input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
  -webkit-appearance: none; 
  margin: 0; 
}