0
I have this field:
<label asp-for="TransportadorID" class="col-md-3 control-label" style="text-align:left;"></label>
<div class="col-md-2">
<input type="text" asp-for="TransportadorID" onkeypress="return BuscaDados1(event);" onblur="CarregaFornecedor1(this.value);" class="form-control" name="TransportadorID" id="idtransportador" />
</div>
He’s the int type ? null, however always when giving the Ubmit it gives Focus to the field, I have already looked and there is no function that does this, what can be happening? This is in editing, in new the empty field works normal. I don’t know what could be going on. Any idea ?
Model:
[Display(Name = "Transportador")]
public int? TransportadorID { get; set; }
Function:
function BuscaDados1(e) {
var idfornecedor = document.getElementById("idtransportador").value;
if (OnEnter(e)) {
if (idfornecedor == "?") { abreModalFornecedor1(); return false; }
else {
CarregaFornecedor1(idfornecedor);
return false;
}
}
else {
return true;
}
}
function CarregaFornecedor1(id) {
var url = "/PedidoVenda/CarregaTransportador";
var id = $("#idtransportador").val();
$.ajax({
url: url
, data: { id: id }
, type: "POST"
, datatype: "html"
, success: function (data) {
console.log('entrou carrega fornecedor 1');
if (data.resultado > 0) {
$("#nometransportador").html(data.nomeFornecedor);
}
else {
if (id != "?" && id != "") {
alert('Transportador não encontrado, tente novamente.');
$("#idtransportador").val("");
$("#nometransportador").html("");
}
}
}
});
}
Function CarregaTransportador
[HttpPost]
public ActionResult CarregaTransportador(int id)
{
try
{
var item = db.Fornecedores.Include(f => f.CategoriaFornecedores).Where(r => r.Id == id && r.CategoriaFornecedores.Transportador == true).Single();
return Json(new
{
nomeFornecedor = item.Nome,
ruaFornecedor = item.Rua,
nFornecedor = item.Numero,
bairroFornecedor = item.Bairro,
cidadeFornecedor = item.Cidade,
Resultado = item.Id
});
}
catch { return Json(new { Resultado = 0 }); }
}
has how to add the template, and functions js?
– Barbetta
@Barbetta added.
– Mariana
You expect a NULL or an if (idfornecedor == "?") ... "?"
– Marco Souza
o ? opens a modal for search. and the void, is because it can be empty.
– Mariana
when you do the
idfornecedor == "?"
in vdd it expects inside the input to have text "?".– Barbetta
Yes, he expects you to have '?' because only with ? and enter, he opens the modal.
– Mariana
@Barbetta because the input type is text, so it accepts the ?
– Mariana
Aaah yes, I understand rsrs, he gets to enter the
CarregaFornecedor1
? if yes, what value the fieldvar id
are receiving?– Barbetta
@Barbetta he does get into
CarregaFornecedor1, o campo
id` is receiving, it is receiving empty.– Mariana
have controller code /Pedidovenda/Loader? can add it, please
– Barbetta
@Barbetta added.
– Mariana
Let’s go continue this discussion in chat.
– Barbetta
@Barbetta managed to solve including the required directly in viewmodel, compiling and soon after removing the required.
– Mariana
@marianac_costa that crazy kkkkkk, but good that solved ;)
– Barbetta