Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The reason you are getting undefined (Assuming value is a string) is because you need to wrap <code>@Model.ServicosID</code> it in quotes, otherwise it will look for the value of the property as the name of the variable, instead you just need to pass the value as the a string.</p> <p>Try this:-</p> <pre><code>@Html.TextBoxFor(model =&gt; model.NumTransportado, new { @class = "form-control input-sm", id = "NumTransResp" + Model.ServicosID + "", name = "NumTransResp" + Model.ServicosID + "", onchange = "PreencheDadosVendedor(this, 3, '" + @Model.ServicosID + "')" }); ^____ ^____ </code></pre> <p>Or better do this, instead of adding an <code>onchange</code> attribute; attach an event instead and make use of <code>data-*</code> attributes to store element specific values, this way you separate out html and js:</p> <p>i.e:</p> <pre><code>@Html.TextBoxFor(model =&gt; model.NumTransportado, new { @class = "form-control input-sm myclass", //Add a class id = "NumTransResp" + Model.ServicosID + "", data_tipoFuncionario = 3, //Add a data attribute name = "NumTransResp" + Model.ServicosID + ""}); </code></pre> <p>and</p> <pre><code>$('.myclass').change(function(e){ var idServicoEdicao = this.id.replace("NumTransResp",""), //get the part from its own id tipoFuncionario = $(this).data("tipoFuncionario"); //get the value from data attribute $.getJSON("/Contrato/getDadosVendedor", { id: this.value, tipoFuncionario: tipoFuncionario }, function (result) { switch (tipoFuncionario) { case 1: $("#NomeVendedor_Contrato").val(result.NomeVendedor); case 2: $("#NomeTransResponsavel").val(result.NomeVendedor); case 3: $("#NomeTransResponsavel_" + idServicoEdicao).val(result.NomeVendedor); } }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload