Postback Checkboxen aus Tabelle Zeilen, die auf MVC Razor Stark Typisierte Ansicht

Ich stark typisierte Darstellung von Daten aus

ViewModel 
    public class GoldSetnUsers
    {
     bool Public { get; set; }
     public List<GSUsers> gsUsers { get; set; }


        public GoldSetnUsers()
        {
            UsersContext _dbm = new UsersContext();
            this.gsUsers = _dbm.UserProfiles.Select(n => new GSUsers { UserName = n.UserName, isEditor = false, isReviewer = false }).ToList();
        }

        public class GSUsers
        {
            public string UserName { get; set; }
            public bool isEditor { get; set; }
            public bool isReviewer { get; set; }
        }

    }

Controller Httpget-Methode in dieser Ansicht angezeigt werden

Postback Checkboxen aus Tabelle Zeilen, die auf MVC Razor Stark Typisierte Ansicht

Problem ist, post-back-Modell gibt alle Zeilen die Kontrollkästchen als falsch. Die check-box, Tisch im freien, Öffentlichkeit, gibt richtigen post-Wert zurück obwohl.

Controller Postback-code

[HttpPost]
    public ActionResult Create(GoldSetnUsers newGS)
    {
        if (ModelState.IsValid)
        {   //newGS gets me value 

          }

}

Ansicht

@model mvc2db.Models.GoldSetnUsers
@using BootstrapSupport;
@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)


         @Html.BeginControlGroupFor(model=>model.Public)
            @Html.LabelFor(model => model.Public,new {@class="control-label"})
        <div class="controls">
            @Html.EditorFor(model => model.Public,new {@class="input-xlarge"})
            @Html.ValidationMessageFor(model => model.Public,null,new{@class="help-inline"})
        </div>
        <div class="controls">
            <table class="table">
    <thead>
    <tr>

        <th>Name</th>
        <th>Reviewer</th>
                <th>Editor</th>

    </thead>
    <tbody>

@foreach (var item in Model.gsUsers) {
    <tr>

        <td>
            @Html.DisplayFor(modelItem => item.UserName)
        </td>

        <td>
            @Html.EditorFor(modelItem => item.isEditor)
        </td>

        <td>
            @Html.EditorFor(modelItem => item.isReviewer)
        </td>



    </tr>
}
</tbody>
</table></div>
@Html.EndControlGroup()

    <div class="form-actions">
            <button type="submit" class="btn btn-primary">Save changes</button>
            <button class="btn">Cancel</button>
          </div>
    </fieldset>
}
InformationsquelleAutor user219628 | 2013-06-19
Schreibe einen Kommentar