0
Javascript function receives values but fields are not receiving values.
Function of the Controller
public JsonResult GetSequencia(DateTime dataAbate)
{
db.Configuration.ProxyCreationEnabled = false;
var lote = db.Lotes.Where(p => p.DataAbate == dataAbate).ToList();
if (lote.Count <= 0)
{
var loteNull = db.Lotes.ToList();
loteNull.Add(new Lote
{
SequenciaInicial = 123,
SequenciaFinal = 456
});
return Json(loteNull);
}
return Json(lote);
}
Javascript function within SECTION SCRIPTS
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
$(document).ready(function () {
$("#DataAbate").change(function () {
$("#SequenciaInicial").empty();
$.ajax({
type: 'POST',
url: '@Url.Action("GetSequencia")',
dataType: 'json',
data: { dataAbate: $("#DataAbate").val() },
success: function (data) {
$.each(data, function (i, data) {
$("#SequenciaInicial").append(data.SequenciaInicial);
$("#SequenciaFinal").append(data.SequenciaFinal);
});
},
error: function (ex) {
alert('Falha ao buscar Proprietario.' + ex);
}
});
return false;
})
});
}
Fields that are not receiving values
<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>
The append is used to insert content at the end of elements. It is correct that you use the
val
to add values.– Marconi
Another thing, your Edit for has no ID. You can modify it to:
@Html.TextBoxFor(x => x.SequenciaInicial, new { id = "SequenciaInicial") })
– Marconi