[Solved] Html.ActionLink not working inside option tag in ASP.Net MVC

on Sep 28, 2021 10:56 PM


html action link not fire when i wrapt it in option

        foreach (var i in Model)
            <option>@Html.ActionLink(i.LangFullName, "ChangeLanguage", "Helper", new { lang = i.LangCultureName }, new { @class = "dropdown-item" })</option>


Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Sep 29, 2021 06:24 AM
on Sep 30, 2021 12:32 AM

Hi nauna,

You can't have an ActionLink inside an option tag.

If you want to move to a link that is selected from a dropdown you need to use change event.

Use an attribute that has the address inside like

<option value="https://www.aspsnippets.com">

Then in change event use the value.

$('#DropDownList').on("change", function () {
    var url = $(this).find('option:selected').val();
    window.location.href = url;