Tengo un foreach que me da una lista de valores que al hacer clic llama a un controlador:
@foreach (var item in Model) { <div>@Html.ActionLink(item.Text, "UpdateController", new { subSectionID = item.Value, subsectionName = item.Text })</div> }Me gustaría hacer esto, pero ahora uso una lista desplegable donde hacer clic en el valor me redirige al controlador.
Si alguien sabe como hacerlo o lo hace de alguna otra forma, tal vez usando Select en html, me ayudaría, gracias!
Prueba lo siguiente:
<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" })Puede encontrar una solución similar aquí: https://stackoverflow.com/a/6088047/6630084