I tried below code in Razor and I'm trying to pass selected item values (from Model.NewList) as a parameter (comma separated strings) in the link (New Link)

@using (Html.BeginForm())
{

    @Html.ActionLink("New Link", 
                        "NewAction", 
                        "NewController", 
                        new { columns = 3,
                              locations = String.Join(",", Model.NewList
                                            .Where(m => m.Checked == true)
                                            .Select(m => m.Code))

                        }, 
                        new { @class = "btn btn-success" })

    for (var i = 0; i < Model.NewList.Count(); i++)
    {
        <table>
            <tr>
                <td>
                    @Html.CheckBoxFor(m => m.NewList[i].Checked)
                </td>
                <td>
                    @Html.HiddenFor(m => m.NewList[i].Code)
                    @Html.DisplayFor(m => m.NewList[i].Name)
                </td>
            </tr>
        </table>
    }
}

Problem with this is it is not picking up the items selectd by user (.Where(m => m.Checked == true) as it runs on page load, when no items are selected. How to update the model as user select the items and pick selected items when clicks on the action link?

Related posts

Recent Viewed