Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
I need to replace ActionLink for Dropdownlist

I'm having a foreach that it gives me a list of values that when click it call a controller:

@foreach (var item in Model)
{
    <div>@Html.ActionLink(item.Text, "UpdateController",
                new { subSectionID = item.Value, subsectionName = item.Text })</div>
}

I would like to do this but now using a dropdown list where clicking on the value redirects me to the controller.

If someone knows how to do it or do it in some other way, maybe using Select in html, it would help me, thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try the following:


 <script type="text/javascript">  
    $('#subsec').change(function () {
        
        var url = $(this).val();               

        if (url != null && url != '') { 
            window.location.href = url;
        }
    });
</script>

@Html.DropDownListFor(m => Model.GetEnumerator().Current,
    Model.Select(d =>
    {
        return new SelectListItem() {
            Text = d.Text,
            Value = Url.Action("Your_Action_Name", "Your_Controller_Name",  new { subSectionID = d.Value, subsectionName = d.Text })

        };
    }),
    "-Select a value-",
    new { id = "subsec" })

A similar solution you can find here: https://stackoverflow.com/a/6088047/6630084

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda