My models

public class User
{
    public string Id { get; set; }

    [Display(Name = "")]
    public bool IsSelected { get; set; }

    [Display(Name = "Nom")]
    public string Name { get; set; }

    [Display(Name = "Prénom")]
    public string Firstname { get; set; }


    public User()
    {
        //ctor
    }
}


public class ListUser
{
    public string ClickedButton { get; set; }

    [Display(Name = "")]
    public List<Models.User> Users;

    public ListUser(List<Models.User> Users)
    {
        //ctor
    }

    public ListUser()
    {
        //ctor
    }
}

index.cshtml

On this page I display all the users from ListUser, each user is selectable with a checkbox

@model Models.ListUser
<!-- some content here -->
<script>
    function clickedButton(i){
        document.getElementById("ClickedButton").value = i;
        return true;
    }
</script>
@using (Html.BeginForm("Index", "Users", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
        {
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            @Html.HiddenFor(m => m.ClickedButton);

            for (var i = 0; i < Model.Users.Count(); i++)
            {
                <div class="one-result">
                    <div class="one-column checkbox-column">
                        <div class="type"></div>
                        <div class="value">@Html.CheckBoxFor(m => m.Users[i].IsSelected)</div>
                    </div><div class="one-column">
                        <div class="type">@Html.DisplayNameFor(m => m.Users[i].Name)</div>
                        <div class="value">@Html.DisplayFor(m => m.Users[i].Name)</div>
                    </div><div class="one-column">
                        <div class="type">@Html.DisplayNameFor(m => m.Users[i].Firstname)</div>
                        <div class="value">@Html.DisplayFor(m => m.Users[i].Firstname)</div>
                    </div>
                </div>
            }
            <div class="submit-buttons">
                <input type="submit" value="RĂ©initialiser les mots de passe" class="btn btn-default" onclick="clickedButton('psw')"/>
            </div>
        }

And here's the controller (this controller is called when I submit the form)

[HttpPost]
public ActionResult Index(ListUser model)
    {
        // I added a breakpoint here            
        return this.RedirectToAction("Index", "Home");
    }

I want to send all the selected users to the controller, for instance when I select 4 users, I want to retrieve them in the controller :enter image description here

The problem : When I submit the form only the ClickedButton field is set in the model, the users I selected (via checkboxes) are not set.

enter image description here

What is the problem?

Related posts

Recent Viewed