Html.ActionLink with an identification value from the drop-down list

I have a drop-down list: <% = Html.DropDownList ("ddlNames", new SelectList (Model.NameList, "ID", "Name"))%>

I have ActionLink: <%: Html.ActionLink ("edit", "Edit", "Members", new {area = "MembersArea", id = XXX}, null)%>

I want the dropdown value in XXX. Therefore, I want to use the values ​​from the controls in the ActionLink view. Is this possible in a simple way?

thank,

Filip

+5
source share
2 answers

, html- , . - javascript. onchange href :

$(function() {
    $('#ddlNames').change(function() {
        var value = this.value; // get the selected value
        // TODO: modify the value of the anchor
    });
});

, , , , .

. , , javascript:

<% using (Html.BeginForm("Edit", "Members", new { area = "MembersArea" })) { %>
    <%= Html.DropDownListFor(x => x.SelectedName, 
        new SelectList(Model.NameList, "ID", "Name"))%>
    <input type="submit" value="Edit" />
<% } %>
+3

, , , .

Razor:

@Html.DropDownList("DropDownFirstNames", new SelectList(Model.FirstNames, "ID", "Name"))
@Html.DropDownList("DropDownLastNames", new SelectList(Model.LastNames, "ID", "Name"))
@Html.ActionLink("Submit name", "ActionName", "ControllerName", null, new { @id = "SubmitName" })

<script type="text/javascript">
    $('#SubmitName').click(function () {
        var first = $('#DropDownFirstNames').val(); 
        var last = $('#DropDownLastNames').val();
        var path = '@Url.Content("~/ControllerName/ActionName")' + "?firstId=" + first + "+&lastId=" + last
        $(this).attr("href", path);
    });
</script>
+3

All Articles