[英]Redirect to a specific view in ASP.NET MVC 5
我正在通過電子郵件發送有關我的網絡管理員的信息,我的控制器/視圖有一個鏈接,因此當用戶單擊該鏈接時,系統應該轉到登錄頁面(我有一個頁面可以這樣做)。
如果登錄正常,我想轉到特定的控制器/視圖/參數。 默認情況下,當登錄正常時,網絡管理員會轉到索引頁面,但我不知道如何定義轉到另一個視圖。
[AllowAnonymous] public JsonResult Login(string usuario, string contrasena) {
Response respuesta = new Response();
LoginVM _usuarioResponse = new LoginVM();
try
{
mensaje = //login in database methid here
if (mensaje == "ok")
{
..
..
..
respuesta.status = Status.Success;
respuesta.message = mensaje;
respuesta.result = Url.Action("Index","Home");
}
else
{
respuesta.status = Status.Error;
respuesta.message = mensaje;
}
}
catch (Exception ex)
{
respuesta.status = Status.Error;
respuesta.message = ex.Message;
respuesta.result = ex.ToString();
}
return Json(respuesta, JsonRequestBehavior.AllowGet);
}
我在登錄后返回主頁上的 url,當用戶單擊電子郵件鏈接時,我想在登錄后轉到另一個視圖
您可以使用RedirectToAction
方法執行此操作:
if (loginSuccessful)
{
return RedirectToAction("SpecificView", new { param1 = value1, param2 = value2 });
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.