C# Razor中的EditorFor字段的最大值无效

C# Razor中的EditorFor字段的最大值无效,c#,asp.net-mvc,visual-studio,razor,editorfor,C#,Asp.net Mvc,Visual Studio,Razor,Editorfor,我有组件和零件,工作和功能都相同,但“Max”和“Min”值不适用于我的editorFor,适用于我的零件,但它们适用于我的组件 这是我查看页面的代码 <h4><u><b>Component(s) Included</b></u></h4> <table class="table"> <tr> <th>

我有组件和零件,工作和功能都相同,但“Max”和“Min”值不适用于我的editorFor,适用于我的零件,但它们适用于我的组件

这是我查看页面的代码

    <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有一个值,我甚至为了测试的目的把它改成了一个数字,但它仍然不起作用。几天前它还在工作,代码中没有任何变化使它无法工作,但验证没有

这似乎是VisualStudio的一个小故障,但我不太确定如何修复它

下面是呈现的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 + ")" } })


可以显示呈现的html吗?-请只写相关部分。@Stefan好的,我是在渲染html时添加的,我实际上是指生成的html,因此;不由浏览器渲染。对不起,我的错。不管怎样,很好,你已经修好了。