Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!