我有一個cshtml頁面,將發送一個項目列表到我的控制器。但是,當我點擊提交按鈕,沒有什麼被傳遞給我的控制器。無法通過數據表向控制器傳遞列表。 ASP.net
下面的代碼是我的cshtml代碼,將模型傳遞給我的控制器。
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-group">
@if (Model.Count() != 0)
{
<input type='button' value='Save and Update' class="btn btn-primary" data-toggle="modal" data-target="#myModal" />
}
</div>
<table class="table cell-border" id="TempTable5">
<tbody>
@if (Model.Count() != 0)
{
int j = 0;
foreach (var item in Model)
{
@Html.HiddenFor(model => item.ExerciseInstruction.ExerciseInstructionID)
<tr>
<td align="center">
<div class="form-group">
@Html.DisplayFor(model => item.ExerciseInstruction.ExerciseInstructionID)
</div>
</td>
<td>
<div class="form-group">
@Html.DisplayFor(model => item.Exercise.Name)
</div>
</td>
<td>
<div class="form-group">
<iframe width="300" height="175" [email protected] frameborder="0" allowfullscreen></iframe>
</div>
</td>
<td align="center">
@Html.DisplayFor(model => item.Therapist.Name)
</td>
<td>
@Html.DisplayFor(model => item.ExerciseInstruction.Prescribed_Date)
</td>
<td>
No. of Reps: @item.ExerciseInstruction.Number_Of_Reps<br />
No. of Secs to hold: @item.ExerciseInstruction.Number_Of_Secs_PositionHold<br />
No. of Sets: @item.ExerciseInstruction.Number_Of_Sets_Per_Day<br />
No. of Times: @item.ExerciseInstruction.Frequency_Per_Week<br />
Remarks: @if (item.ExerciseInstruction.Remark == null || item.ExerciseInstruction.Remark.Trim() == "")
{
@:NIL
}
else
{
@item.ExerciseInstruction.Remark
}
</td>
<td align="center">
@Html.EditorFor(model => item.ExerciseInstruction.ToPerform, new { htmlAttributes = new { style = "width:23px; height:23px;" } })
</td>
<td>
@Html.ActionLink("View", "Details", new { id = Model[j].ExerciseInstruction.ExerciseInstructionID, pageFrom = "performExercises" }, new { target = "_blank" })
</td>
</tr>
j++;
}
}
</tbody>
</table>
@if (Model.Count() != 0)
{
<input type='submit' value='Save and Update' class="btn btn-primary" data-toggle="modal" data-target="#myModal" />
}
}
正在處理此問題的控制器如下所示。
[HttpPost]
[ValidateAntiForgeryToken]
[Authorize(Roles = "Therapist")]
public ActionResult ToPerformExercises(int? pid, List<AssignmentViewModel> avmLIst)
{
if (ModelState.IsValid)
{
foreach (var item in avmLIst)
{
ExerciseInstruction eI = db.ExerciseInstructions.SingleOrDefault(a => a.ExerciseInstructionID == item.ExerciseInstruction.ExerciseInstructionID);
eI.ToPerform = item.ExerciseInstruction.ToPerform;
db.Entry(eI).State = EntityState.Modified;
db.SaveChanges();
}
}
return RedirectToAction("ViewToPerform", "AssignExercisesViewModel", new { pid = pid });
}
這是提交彈出框
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!— Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Confirmation</h4>
</div>
<div class="modal-body">
<p>Are you sure you want to add/remove the Ongoing Exercise(s) for the patient?</p>
</div>
<div class="modal-footer">
<input type="button" class="btn btn-primary" value="Confirm" onclick="DisableButton(this)" />
<button type="button" class="btn btn-default" data-dismiss="modal" id="cancel">Cancel</button>
</div>
</div>
</div>
</div>
我的問題是非常相似,這個鏈接Jquery tool DataTable unable to post/submit in an MVC3 Html.BeginForm 但是我不確定他到底是解決這個問題的解釋對他的回答是真的簡單。
任何人都可以協助嗎?
這裏有很多不相關的代碼,問題是缺少一些關鍵代碼。 (即控制器動作。)您能否提供一個簡單而完整的問題示例?你如何將值傳遞給控制器?實際包含在表單文章中的內容是什麼?控制者期望什麼? – David
好的更新了問題。:D – Ugine