Is there anyway to make actionlinks work inside a

2019-08-31 02:16发布

问题:

Is there anyway to make this work:

<select>
        <option>@Html.ActionLink("View", "View", "Person")</option>
        <option>@Html.ActionLink("Edit", "Edit", "Person")</option>
    </select>

So it's basically a dropdown full of links. When you click a link it should direct to the action method like a normal ActionLink helper.

回答1:

You can handle the change event of the select to open the links, like this:

html:

<select>
    <option>@Url.Action("View", "View", "Person")</option>
    <option>@Url.Action("Edit", "Edit", "Edit")</option>
</select>

javascript:

$('select').change(function(){ window.href = $(this).find(':selected').text();});