Call other data from an entity

0

I created a database entity and a dropdownlist. When I click on a list item, I want to call the other data. How do I do it?

Follow code

    public ActionResult dbExample()
    {
        copaDBEntities entity = new copaDBEntities();
        var getCopaList = entity.copa.ToList();
        SelectList list = new SelectList(getCopaList, "id", "ano");
        ViewBag.copalistano = list;

        return View();
    }
}

js

<script type="text/javascript">
$("#CopaList").change(function () {
    $("#msg").text("A copa de " + $("#CopaList option:selected").text() + " teve como país(es) sede(s) : " + 

        + "O Campeão foi " +  + "O Vice Campeão foi " + 
       )
})

image

    
asked by anonymous 14.05.2018 / 20:26

1 answer

0

You take this example as a basis:

public async Task<JsonResult> SelecionarPorProjeto(int id)
    {

        copaDBEntities entity = new copaDBEntities();
        var getCopaList = entity.copa.ToList();

        //Retorna o valor em JSON
         return Json(getCopaList, JsonRequestBehavior.AllowGet);
    }

In View

 <script>
        $("#CopaList").change(function () {
            $.ajax({
                url: "/Subprojetos/SelecionarPorProjeto/" + id,
                success: function (data) {
                    $("#SubprojetoId").empty();
                    $("#SubprojetoId").append('<option value>Selecione...</option>');
                    $.each(data, function (index, element) {
                        $("#SubprojetoId").append('<option value="' + element.ProjetoId + '">' + element.Text + '</option>');
                    });
                }
            });
        });
    </script>
    
04.09.2018 / 18:52