[英]max value is not working for the EditorFor field in Razor
我有组件和零件,工作和 function 相同,但 'Max' 和 'Min' 值不适用于我的编辑器,但它们适用于我的组件?
这是我的视图页面的代码
<h4><u><b>Component(s) Included</b></u></h4>
<table class="table">
<tr>
<th>
Actual Qty Received
</th>
<th>Date</th>
<th>Notes</th>
</tr>
<tr>
@if (Model.Components != null)
{
var orderedcomps = Model.dynamicComp_qty != null ? (int)Model.dynamicComp_qty : (int)Model.comp_qty;
int receivedcomps = Model.actual_comp_qty != null ? (int)Model.actual_comp_qty : 0;
var compremain = orderedcomps - receivedcomps;
<td>
@Model.Components.ComponentIDLink
</td>
<td>
@Html.DisplayFor(model => model.Components.Name)
</td>
<td>
@compremain
</td>
<td>
@if (disableInput)
{
@Html.EditorFor(model => model.actual_comp_qty, new { htmlAttributes = new { @disabled = "true" } })
}
else
{
if (compremain < 0)
{
@Html.EditorFor(model => model.actual_comp_qty, new { htmlAttributes = new { @Value = 0, max = 0, min = compremain, onchange = "updateRows(this," + Model.Components.ID + ")" } })
}
else {
@Html.EditorFor(model => model.actual_comp_qty, new { htmlAttributes = new { @Value = 0, max = compremain, min = 0, onchange = "updateRows(this," + Model.Components.ID + ")" } })
}
}
</td>
<td></td>
}
</tr>
</table>
<h4><u><b>Part(s) Included</b></u></h4>
<table class="table">
<tr>
<th>
Actual Qty Received
</th>
<th>Date</th>
<th>Notes</th>
</tr>
<tr>
@if (Model.Parts != null)
{
var orderedparts = Model.dynamicPart_qty != null ? (int)Model.dynamicPart_qty : (int)Model.part_qty;
int receivedparts = Model.actual_part_qty != null ? (int)Model.actual_part_qty : 0;
var partremain = orderedparts - receivedparts;
<td>
@if (disableInput)
{
@Html.EditorFor(model => model.actual_part_qty, new { htmlAttributes = new { @disabled = "true" } })
}
else
{
if (partremain < 0)
{
@Html.EditorFor(model => model.actual_part_qty, new { htmlAttributes = new { @Value = 0, max = 0, min = partremain, onchange = "updateRows(this," + Model.Parts.ID + ")" } })
}
else
{
@Html.EditorFor(model => model.actual_part_qty, new { htmlAttributes = new { @Value = 0, max = partremain, min = partremain, onchange = "updateRows(this," + Model.Parts.ID + ")" } })
}
}
</td>
}
</tr>
我已经验证了 partremain 有一个值,我什至将它更改为一个用于测试目的的数字,但它仍然不起作用。 几天前它还在工作,代码中没有任何变化使其无法正常工作,但验证却没有。
这似乎是 Visual Studio 故障,但我不太确定如何修复它
这是渲染的 html
该组件只允许我输入 0-5
但我可以输入我想要的任何数量
更新:
通过更改我的 editorFor 来修复它看起来像这样
@Html.EditorFor(model => model.actual_part_qty, new { htmlAttributes = new { type = "number", max = partremain, min = 0, step = 1, onchange = "updateRows(this," + Model.Parts.ID + ")" } })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.