Asp Net MVC Dropdownlist Mustache

Asked

Viewed 51 times

-1

in my application when the user clicks to include performing two queries and each returns (id and name), I set up a mustache template, and would like to load this data in two dropdownlist. the question is how to load this data.

 $(document).on('click', '#btn_incluir', function () {
        
           var btn = $(this);

                if ("#txt_horaI" == "HH:MM") {
                    message: "Campo Hora Incial não pode ser vazio";
                }
                else if ("#txt_horaF" == "HH:MM") {
                    message: "Campo Hora Final não pode ser vazio";
                }
                else {
                    var url = '@Url.Action("RecuperarA", "Operacao")',
                        
                        dadosA = { 
                            carros                          
                        };
                      var url = '@Url.Action("RecuperarP", "Operacao")',
                        dadosB = { 
                        motorista
                        };
                     incluir_linha_produto();
                }
            })
            
            
             function incluir_linha_produto() {

            $('#grid tbody').append(Mustache.render($('#template-produto').html() ));
        }
        
         <script id="template-produto" type="x-tmpl-mustache">
        <tr>
            <td>
                <input class="form-control form-control-sm" type="text" placeholder="De">
            </td>
            <td>
                <input class="form-control form-control-sm" type="text" placeholder="Para">
            </td>
            <td>
                <input class="form-control form-control-sm" type="text" placeholder="Cliente">
            </td>
            <td>
                <select id="Motrista"><option selected="selected" value="">Motorista</option></select>
            </td>
            <td>
                <select id="carro"><option selected="selected" value="">carro</option></select>
            </td>            
            <td>
                <input class="form-control form-control-sm" type="text" placeholder="Tempo">
            </td>
            <td>
                <a class="btn btn-warning btn_remover" role="button">
                    <i class="glyphicon glyphicon-trash"></i>
                </a>
            </td>
        </tr>
    </script>
I can get to dataA and dataB after that I’m lost. I don’t know how to continue.

  • Easier to win in the mega sena than to show a superb guide.

  • ai you look at several closed questions, without even giving the min of attention.Ha excuse here if you value the subjective quality very much.

  • It is that it was not very clear what you need... Why nobody guides... You need to recover the data and mount a select this? Example a motorist combo that?

  • Edenilson, as I said, I can get to the controller where I can have an Actionresult or a Jsonresult(I’m trying both ways because I’m studying) what I don’t know how to do is load the data into a mustache dropdownlist. here

  • <select id="Motrista"><option Selected="Selected" value="">Driver</option></select> as I load the data from here for example public Jsonresult Recuperarnn(string DT, string HI, string HF) { var Listaa = Operacaomodel.Recuperarlistamotoristan(DT, HI, HF); Return Json(Listaa ); }

  • I’ll put as I do here, it may be useful, but I don’t use Actionresult Json usage

  • Mustache would be a Bootstrap-like framework?

  • yes.. I was testing the two ways both by Actionresult and by Json.

Show 3 more comments

1 answer

0

I did it and it worked. $(Document). ready(Function() { $("#btn_include"). click(Function() { var f = {}; f. url = '@Url.Action("Recuperarnn", "Operation")'; f. type = "POST"; f. dataType = "json"; f. data = JSON.stringify({ Dt: $('#txt_data').val(), HI: $('#txt_horaI').val(), HF: $('#txt_horaF').val() }); f. contenttype = "Aplication/json"; f. Success = Function (r) { $("#Aeroi"). Empty(); $("#Aeroi"). prepend("option value='' Selected='Selected'>"); for (var i = 0; i < r.length; i++) { $("#Aeri"). append('' + r[i].Ae + '); } }; $. ajax(f); });

    });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.