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", 
                        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++)
                    @Html.CheckBoxFor(m => m.NewList[i].Checked)
                    @Html.HiddenFor(m => m.NewList[i].Code)
                    @Html.DisplayFor(m => m.NewList[i].Name)

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