Add a Dropdownlistfor with the result of Jquery Asp.net mvc

Asked

Viewed 28 times

0

I want to know how to do this in the friendliest way possible.

I have an Actionresult

public ActionResult IncluirProspecto()
{

    //retorna o cadastro classificação do prospecto
    var tbuscarClassificacaoProspecto = new ClassificacaoProspectoAplicacao();
    var listaClassificacao = tbuscarClassificacaoProspecto.ListarTodos();
    ViewBag.LocalClassificacao = new SelectList(listaClassificacao, "IDCLASSIFICACAOPROSPECTO", "DESCRICAO");

    //retorna a categoria do prospecto
    var tbuscarCategoriaProspecto = new CategoriaProspectoAplicacao();
    var listaCategoria = tbuscarCategoriaProspecto.ListarTodos();
    ViewBag.LocalCategoria = new SelectList(listaCategoria, "IDCATEGORIA", "DESCRICAO");



    return View();
}

In view I have:

<div class="col-md-3 form-group">
    @Html.Label("Classificação:")
    @Html.DropDownListFor(x => x.IDCLASSIFICACAOPROSPECTO, ViewBag.LocalClassificacao as SelectList, new { @class = "form-control", id = "ProjetoId", required = "required" })
</div>

<div class="col-md-3 form-group">
    @Html.Label("Categoria:")
    @Html.DropDownListFor(x => x.IDCATEGORIA, ViewBag.LocalCategoria as SelectList, new { @class = "form-control",  required = "required" })
</div>

This way I can bring the two Dropdownlistfor with the data now, as I can do the Viewbag.Locationthe search data according to the Viewbag.Locationcategory

On the controller I did so:

public JsonResult SelecionarCategoriaProspecto(int? id)
{

    var tbuscarClassProspecto = new CategoriaProspectoAplicacao();
    var listaClassificacao = tbuscarClassProspecto.ListarPoIdClassificacao(Convert.ToInt32(id));
    return Json(listaClassificacao, JsonRequestBehavior.AllowGet);
}

How to add the answer inside Dropdownlistfor

  • @Randrade, the answer presented there, was not very clear, was damaged the understanding.

  • Your question is the same. The answers there are the ways to do what you want. To do this, you will need to use js to do this. If you don’t know much about javascript, I don’t think any answers would help you. I would advise you to see the examples on google to better understand. Everything is the "same thing", but in different ways. Perhaps with more examples you could better understand.

No answers

Browser other questions tagged

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