简体   繁体   English

最大值不适用于 Razor 中的 EditorFor 字段

[英]max value is not working for the EditorFor field in Razor

I have components and parts, both work and function the same but the 'Max' and 'Min' values aren't working for my editorFor's for my parts but they are working for my components?我有组件和零件,工作和 function 相同,但 'Max' 和 'Min' 值不适用于我的编辑器,但它们适用于我的组件?

Here is my code for my view page这是我的视图页面的代码

    <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>

I have verified that partremain has a value and I even changed it to a number for testing purposes but it still doesn't work.我已经验证了 partremain 有一个值,我什至将它更改为一个用于测试目的的数字,但它仍然不起作用。 It was working a few days ago and nothing has changed in code to have it not work but the validation isn't.几天前它还在工作,代码中没有任何变化使其无法正常工作,但验证却没有。

This seems like an Visual Studio Glitch but I'm not too sure how to fix it这似乎是 Visual Studio 故障,但我不太确定如何修复它

Here is the rendered html这是渲染的 html

UI用户界面

The component only lets me enter 0-5该组件只允许我输入 0-5

but I can enter any qty I want for the part但我可以输入我想要的任何数量

Update:更新:

Fixed by changing my editorFor to look like this通过更改我的 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM