1

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 つあります。

  1. 入力に基づいてレコードを検索します。

  2. レコードを編集します。

各関数を actionResult に入れます。ActionResult インデックスはうまく機能しますが、actionResult 検索は機能しません。設定したブレークポイントにイベントが行きませんでした。

4

2 に答える 2

0

そうであれば、検索メソッドで Group のオブジェクトを取得しようとしています。ビューは Group モーダルで強く型付けする必要があります

それ以外の場合は、検索アクション メソッドを修正してください

[HttpPost]
 public ActionResult Search(int? GroupId) { 
     List<Group> listResult = ListGroup.Where(m=>m.GroupID == GroupId).ToList();
     return View("Index", listResult);
 }
于 2015-07-13T06:26:11.530 に答える