html弹出表单始终返回第一个值

时间:2018-09-04 09:48:34

标签: c# html model-view-controller

这是C#MVC代码,其中从数据库搜索记录后,我试图在每行(正在运行)中显示记录。每行包含Update School按钮以及其他详细信息,包括ChdId。单击此按钮后,我的视图应返回schId (从下拉列表中选择学校之后)和对应于该行的ChdId。但是提交任何行的Update School后,我总是在我的控制器(不是我要更新的行)中获得第一行的ChdId

>

问题

以前有没有人遇到过这个问题?还是没人知道为什么会这样,或者我做错了什么?

请在下面查看我的代码,感谢您检查我的问题!

控制器

[HttpPost]
public ActionResult UpdateSchool(int SchoolNames, int ChdId, Child model)
{

}

查看

@model Ass4Final.Models.Child

@{
    ViewBag.Title = "Search";
    var listOfSchoolNamesAndIds = ViewBag.SchoolNameAndId;
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
    <script src="~/scripts/jquery-1.10.2.min.js"></script>
    <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
    <script src="~/JS/Search.js"></script>

    <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>

<body>
    <h2>Search</h2>
    <br /> <br />
           <div>
               <table class="table" id="myTable" style="width:100%">
                   <tr>
                       <th>
                           @Html.Label("Child ID")
                       </th>
                       <th>
                           @Html.Label("Child Name")
                       </th>
                       <th>
                           @Html.Label("DOB")
                       </th>
                       <th>
                           @Html.Label("School Name")
                       </th>
                       <th></th>
                   </tr>

                   @foreach (var item in Model.DataChdNamCurrSchDOBProp)
                   {
                       <tr>
                           <td>
                               @item.ChdId
                           </td>
                           <td>
                               @item.ChdName
                           </td>
                           <td>
                               @item.DOB
                           </td>
                           <td>
                               @item.School
                           </td>
                           <td>
                               <div data-role="main" class="ui-content">
                                   <a href="#myPopup" data-rel="popup" class="ui-btn ui-btn-inline ui-corner-all ui-icon-check ui-btn-icon-left">Update School</a>

                                   <div data-role="popup" id="myPopup" class="ui-content" style="min-width:250px;">
                                       @using (Html.BeginForm("UpdateSchool", "Home", FormMethod.Post))
                                       {
                                           <h3>Enter New School</h3>
                                           @Html.DropDownList("SchoolNames", new SelectList(ViewBag.SchoolNameAndId, "schId", "schName"), "Select New School", new { @id = "MySearch" })
                                           <input type="hidden" value="@item.ChdId" name="ChdId" />
                                           <input type="submit" data-inline="true" value="UpdateSchool">
                                       }
                                   </div>
                               </div>
                           </td>
                       </tr>
                   }

               </table>
           </div>
</body>
</html>

0 个答案:

没有答案