Dropdown Asp.net MVC

0

I would like to do two dropdowns in a view, I do not want to do these dropdowns through the model in the view because each dropdown is of a different class.

I made the dropdowns with angular.js only because I could not get the values when submitting the form.

I would like to do these dropdowns with Get call via Json or Ajax.

    
asked by anonymous 23.02.2016 / 18:42

1 answer

0

Friends got popular DropDownList via ajax as follows:

Controller:

public ActionResult GetAntera()
    {
        var List = db.Antera.ToList();
        return this.Json(List, JsonRequestBehavior.AllowGet);
    }

Script

function Teste() {
    $.ajax({
        url: "/Angiosperma/GetAntera/",
        success: function (data) {
            $("#teste").empty();
            $("#teste").append('<option value>Selecione...</option>');
            $.each(data, function (index, element) {
                $("#teste").append('<option value="' + element.Id + '">' + element.NOME + '</option>');
            });
        }
    });
}

$(document).ready(function () {

    Teste();
});

View:

<select id="teste" name="teste" ></select>
    
24.02.2016 / 01:57