Dropdown Asp.net MVC

Asked

Viewed 110 times

0

I would like to do two dropdown in a view, I don’t want to dropdown through the model in the view because each dropdown is a different class.

I made the dropdowns with angular.js only that I failed to get the values when submitting the form.

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

  • You can edit your question by putting in it the code already developed?

  • You want with Angular? Maybe this answer can help you. Just make the request Ajax when loading the page.

1 answer

0


Friends got popular the 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>

Browser other questions tagged

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