DropDownList
is a result of selecting a DropDownList
before it, I created a function with javascript
and ajax
to perform the filter, everything works when javascript
is within cshtml
, but when I split the function into a .js
file, I can no longer call the action
within controller
.
Below is the piece of code where I want to call the function that is in the file javascript
:
<div class="col-sm-3 col-xs-12">
<div class="form-group">
@Html.DefaultLabelFor(model => model.CompanhiaId)
@Html.EditorFor(model => model.CompanhiaId, new { Items = Model.CompanhiaList , @onchange = "diretoria(1,'listarByCompany','skill')" } )
@Html.ValidationMessageFor(model => model.CompanhiaId)
</div>
</div>
And here is the function that stays in the file javascript
:
$.ajax({
type: "POST",
url: "@Url.Action('listarByCompany','skill')",
data: {
id: id
},
success: function ajaxSucceess(response) {
var dir = $("#DiretoriaExecutivaId").empty(); //Removendo todos os itens
dir.append($("<option>Selecione...</option>"));
$.each(response, function (i, response) {
dir.append($('<option>', {
value: response.Value,
text: response.Text
}));
});
}
});
Does anyone know how to do this?