use*_*646 11 asp.net-mvc razor
我有一个int值,我想呈现为数字向下,ID为"Quantity",所以我在剃刀中执行以下操作:
<div class="field-label">@Html.LabelFor(m => model.Quantity)</div>
<div class="field-editor">@Html.EditorFor(m => model.Quantity, null, "Quantity")</div>
Run Code Online (Sandbox Code Playgroud)
在chrome中,这给了我正确的UI,但是我想设置min,max和default值,所以它的工作方式类似于下面的代码.
<input id="Quantity" type="number" name="quantity" min="0" max="10" value="0" >
Run Code Online (Sandbox Code Playgroud)
小智 23
您可以通过@ Html.EditorFor函数的"object AddiditonalViewData"重载来完成此操作.然后像这样指定htmlAttributes:
@Html.EditorFor(m => Model.Quantity, new {htmlAttributes = new {min = 0, max = 20} } )
Run Code Online (Sandbox Code Playgroud)
请注意,无论您在htmlAttributes中定义了什么,"value"都设置为Quantity属性的实际值.
| 归档时间: |
|
| 查看次数: |
16725 次 |
| 最近记录: |