代わりに、次のようなコントローラーを使用することをお勧めします。
public class InstitutionController : Controller
{
public ViewResult Index()
{
return View(); // Keep it simple, load data via JSON instead
}
[HttpPost]
public JsonResult Load()
{
// Go get Institutions etc
return Json(institutions);
}
[HttpPost]
public JsonResult Save(Institutions[] institutions)
{
try
{
// Save the institutions to the DB
}
catch (Exception ex)
{
return Json(new { Message = "Error." });
}
return Json(null); // Or some other way of saying it worked
}
}
つまり、View に渡す Model はブラウザによって永続化されません。代わりに、サーバーが応答を生成している間、サーバー メモリに一時的に保持されます。
ただし、上記の例では、たとえば jquery を使用して JSON を介してサーバーからモデルをロードするビューを作成できます。これにより、ページの存続期間中、ブラウザーで保持できます。ユーザーが機関または機関に変更を加えた場合、上記の Save() のようなメソッドを使用して、新しいデータまたはデータの変更をサーバーに送信し、データベースに保存できます。