How to do interaction between InputText + Javascript between Controller and View in Asp.Net MVC

0

I have the following problem ( For better explanation we have attached image ).

Image link

Owner 1 arrives with 100 oxen;

Owner 2 arrives with 30 oxen;

Owner 3 arrives with 50 oxen.

The procedure for these steers to be vaccinated in sequence is this. Register the Owners as Lots, leaving each field with your persisted data as in the example below:

DataVacination: 05/03/2018 | Lot: 1 | Privacy Policy | SeqInicio: 1 | SeqFim: 100; Date of publication: 05/03/2018 | Lot: 2 | About Us | SeqInicio: 101 | SeqFim: 130; Date of publication: 05/03/2018 | Lot: 3 | Privacy Policy | Seq Home: 131 | SeqFim: 180.

In the Create Screen I have the Vaccination Date Field which, when finished, must access the Controller function and search the last registered SeqFim and fill in the InputText Sequence Start by adding + 1

To end the Sequence, simply type Qty Animals and the InputText Sequence End receives the end of the Range.

Controller Create has the following function

    public JsonResult GetSequencia(DateTime data)
    {
        db.Configuration.ProxyCreationEnabled = false;
        var lote = db.Lotes.Where(p => p.Data == data).LastOrDefault();
        return Json(lote);
    }

The View has the following script

<script type="text/javascript">
        $(document).ready(function () {
            $("#QuantidadeAnimais").change(function () {
                $("#SequenciaInicial").empty();
                $("#SequenciaInicial").append('0');
                $.ajax({
                    type: 'POST',
                    url: '@Url.Action("GetSequencia")',
                    dataType: 'json',
                    data: { data: $("#Data").val() },
                    success: function (data) {                        
                        $("#SequenciaInicial").append('1001');                        
                    },
                    error: function (ex) {
                        alert('Falha ao buscar Sequencia.' + ex);
                    }
                });
                return false;
            })
        });
</script>

The fields within View Create

[![<div class="form-group">
            @Html.LabelFor(model => model.QuantidadeAnimais, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.QuantidadeAnimais, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.QuantidadeAnimais, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.DataAbate, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.DataAbate, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.DataAbate, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.SequenciaInicial, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.SequenciaInicial, new { htmlAttributes = new { @class = "form-control", disabled = "disabled" } })
                @Html.ValidationMessageFor(model => model.SequenciaInicial, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.SequenciaFinal, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.SequenciaFinal, new { htmlAttributes = new { @class = "form-control", disabled = "disabled" } })
                @Html.ValidationMessageFor(model => model.SequenciaFinal, "", new { @class = "text-danger" })
            </div>
        </div>][1]][1]
    
asked by anonymous 05.03.2018 / 22:29

0 answers