2017-05-26 67 views
0

我想从剃须刀视图检索到出勤管理员的学生。在一行中,我想访问单选按钮值。而且有很多行。我如何一次访问所有行数据并将其发送给控制器?从窗体检索学生出勤数据到控制器

我的Razor视图是:

<table class="table"> 
         <thead class="thead-inverse"> 
          <tr> 

           <th>Full Name</th> 
           <th>Roll No</th> 
           <th>Status</th> 

           @* <th>Status</th>*@ 
          </tr> 
         </thead> 
         <tbody> 
          @using (@Html.BeginForm("Save", "Attendance", FormMethod.Post, new { @class = "form-horizontal" })) 
          { 

           foreach (var student in Model.Students) 
           { 
            <tr> 
             <td>@student.Name</td> 
             <td>@student.RollNo</td> 
             <td> 

              <div data-toggle="buttons"> 
               <label class="btn btn-success active"> 
                <input type="radio" name="options" id="1" autocomplete="off" checked> Present 
               </label> 
               <label class="btn btn-danger"> 
                <input type="radio" name="options" id="2" autocomplete="off" checked> Absent 
               </label> 
               <label class="btn btn-primary"> 
                <input type="radio" name="options" id="3" autocomplete="off" checked> On Leave 
               </label> 
               <label class="btn btn-warning"> 
                <input type="radio" name="options" id="4" autocomplete="off" checked> Short Leave 
               </label> 
              </div> 
             </td> 
            </tr> 

           } 
           <div class="form-group"> 
            <div class="col-lg-10 col-lg-offset-2"> 
             <button type="submit" class="btn btn-success">Submit</button> 
            </div> 
           </div> 

          } 
         </tbody> 
        </table> 

我重视我的网页的屏幕截图,让你可以看到我想要达到的目标。

​​

回答

0

不知道,如果你已经尝试过,也许回传一个的FormCollection在HttpPost。下面是一个简单的例子:

[HttpPost] 
    public ActionResult Save(FormCollection form) 
    { 
     //form variable should contain data from form controls. 
     return View(); 
    } 
0

您可以通过的学生名单给控制器:

[HttpPost] 
public ActionResult Save(List<Students> students) 
{ 
    //here you can manipulate that list 
    return View(); 
} 

确保在视图中传递凡提交或创建所有学生“全选”按钮