ウィザードのような機能を備えたサイトを作成するために使用している非常に大きな (77 アクション) コントローラーがあります。このサイトは、管理コンポーネントやエンドユーザー コンポーネントなどの複数のコンポーネントを備えた「ジョブ アプリケーション マネージャー」のようなものです。私が扱っているコンポーネントは、ユーザーが実際に求人応募に記入する部分です。他のコンポーネントで物事が構造化されている方法では、すべてのジョブアプリケーションを同じコントローラーに配置するのが最も理にかなっています。これらのアクションはすべて似たようなことを実行しますが、次のようにモデルが異なります。
public class ExampleController : Controller
{
public ActionResult Action1()
{
Guid appId = new Guid(Session["AppId"].ToString());
... // logic to pull up correct model
return View(model)
}
[HttpPost]
public ActionResult Action1(FormCollection formValues)
{
Guid appId = new Guid(Session["AppId"].ToString());
... // logic to update the model
return RedirectToAction("Action2");
}
public ActionResult Action2()
{
Guid appId = new Guid(Session["AppId"].ToString());
... // logic to pull up the correct model
return View(model)
}
... // on and on and on for 74 more actions
}
アクションのすべてにある一定の冗長性の一部を減らす方法はありますか? これが私が考えていることです:
- メンバー変数 Guid を作成して appId を格納し、OnActionExecuting をオーバーライドしてこの変数を設定します。これは良い考えですか?
- アクションの数を減らすために、ある種のページングを実装します。それを行う方法に関する提案はありますか?