2014-03-05 44 views
0

我有一个观点,该模型是IEnumerable。该视图是在创建具有读写操作的新控制器时创建的mvc基本视图。 我不希望编辑动作会调用不同的视图,我想在索引视图中添加一个按钮,通过按下特定行中的按钮,按钮将调用与“按下”模型的动作结果,并从那里,逻辑将继续。将ViewModel传递给ActionResult mvc4

@model IEnumerable<V1_ILotto.Areas.Admin.Models.WithdrawalModel> 

@{ 
    ViewBag.Title = "בקשות משיכה"; 
} 

<h2>בקשות משיכה</h2> 

@using (Html.BeginForm("Approve", "Withdrawals", FormMethod.Post)) 
{ 
    @Html.AntiForgeryToken() 
    @Html.ValidationSummary(true) 

    <table> 
     <tr> 
      <th> 
       @Html.DisplayNameFor(model => model.User) 
      </th> 
      <th> 
       @Html.DisplayNameFor(model => model.WithdrawalAmount) 
      </th> 
      <th> 
       @Html.DisplayNameFor(model => model.Balance) 
      </th> 
      <th> 
       @Html.DisplayNameFor(model => model.IsApproved) 
      </th> 
      <th></th> 
     </tr> 

     @foreach (var item in Model) 
     { 
      <tr> 
       <td> 
        @Html.DisplayFor(modelItem => item.User) 
       </td> 
       <td> 
        @Html.DisplayFor(modelItem => item.WithdrawalAmount) 
       </td> 
       <td> 
        @Html.DisplayFor(modelItem => item.Balance) 
       </td> 

       <td> 
        <p> 
         <input type="submit" value="Submit" /> 
        </p> 
       </td> 

      </tr> 
     } 
    </table> 
} 

的控制器

[HttpPost] 
     public ActionResult Approve(WithdrawalModel withdrawalmodel) 
     { 
      if (ModelState.IsValid) 
      { 
       //logic for updating the db 
       return RedirectToAction("Index"); 
      } 
      return View(withdrawalmodel); 
     } 

注:视图是在没有得到仅

回答

1

为助手单个模型,但IEnumerable的该模型的(除了显示器)的领带数据发送到模型。如果你想要的数据传回,你需要把你的价值至少在一个隐藏的

@Html.HiddenFor(x => x.Balance) 

+0

在我做到了简单结束。使用ActionLink编辑模式,添加id并调用db逻辑。谢谢 – danny

相关问题