Calling other data from an entity

Asked

Viewed 26 times

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 ??

Follows 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

inserir a descrição da imagem aqui

  • How so "call the other data", can explain better?

  • in code c# only shows the year. I want to show the headquarters, the champion and the vice this year.

  • You will need to make a request to c# to get the rest of the data.

1 answer

0

You have 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);
    }

Na 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>

Browser other questions tagged

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