max value is not working for the EditorFor field in Razor

145 views Asked by At

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?

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

Here is the rendered html

UI

The component only lets me enter 0-5

but I can enter any qty I want for the part

1

There are 1 answers

0
AudioBubble On

Update:

Fixed by changing my editorFor to look like this

 @Html.EditorFor(model => model.actual_part_qty, new { htmlAttributes = new { type = "number", max = partremain, min = 0, step = 1, onchange = "updateRows(this," + Model.Parts.ID + ")" } })