1 つのコントローラーに 3 つの actionResults があり、すべての actionResults が次のコードのように 1 つのビューを返すようにします。
コントローラーで:
public ActionResult Index()
{
return View(ListGroup);
}
[HttpPost]
public ActionResult Index(List<Group> listModel) {
@ViewBag.Success = "Update Suceess";
return View(listModel);//I set break point here
}
[HttpPost]
public ActionResult Search(Group ModelSearch) {
List<Group> listResult = ListGroup.Where(m=>m.GroupID == ModelSearch.GroupID).ToList();
return View("Index", listResult);
}
ビューでは、次の 2 つのフォームがあります。
@using (Html.BeginForm("Search", "DisplayTable"))
{
<fieldset>
<legend>Search</legend>
<input type="text" name="GroupID" />
<input type="submit" value="SEARCH" />
</fieldset>
}
@using (Html.BeginForm("Index", "DisplayTable", FormMethod.Post))
{
var i = 0;
<table>
<tr>
<td>Name</td>
<td>GroupID</td>
</tr>
@foreach(var item in Model){
<tr>
<td>@Html.TextBoxFor(m => m[i].Name)</td>
<td>@Html.TextBoxFor(m => m[i].GroupID)</td>
</tr>
i++;
}
</table>
<input type="submit" value="SAVE" />
}
このコントローラーでやりたいことが 2 つあります。
入力に基づいてレコードを検索します。
レコードを編集します。
各関数を actionResult に入れます。ActionResult インデックスはうまく機能しますが、actionResult 検索は機能しません。設定したブレークポイントにイベントが行きませんでした。