正解です。クリック時にイベントは発生しません。ただし、はるかに単純な解決策があり、MVCはフォームの送信とリダイレクトを非常にうまく処理します。最後にアクセスしたURLを保存するには、コントローラーでアクションフィルターを使用できます。次に、リダイレクトを処理するために、2つのログイン関数を作成します。1つはGETリクエストを処理し、もう1つはPOSTリクエストを処理します。POSTリクエストでは、認証を確認した後、CookieからURL(またはアクション)を取得し、ユーザーをリダイレクトします。
これは次のようになります。
[HttpGet]
public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult Login(LoginViewModel model)
{
if (authenticated)
{
//get cookie information
HttpCookie cookie;
cookie = Request.Cookies["StoredURLFromLastSession"];
String StoredURLFromLastSession = cookie.Value;
//Choose one of these redirect methods
//returns to a hard coded URL
//return Redirect(StoredURLFromLastSession);
//redirects to a route (using routes created in global.asax
//return RedirectToRoute(StoredURLFromLastSession);
//redirects to a specific action/controller
//return RedirectToAction(StoredURLFromLastSession);
}
}
お役に立てれば。