簡體   English   中英

c#mvc3加載不同的視圖

[英]c# mvc3 load a different view

我正在檢查用戶是否經過身份驗證,如果用戶未經過身份驗證,則需要指向其他視圖。

public ActionResult UserMaintenance()
{

  if (User.Identity.IsAuthenticated)
  {
    return View();
  }
  else
  {
    LogOn.View;   //// this is the area that needs help
  }
}

我想向用戶提供輸入登錄名和密碼的視圖....

謝謝

您可以將RedirectToAction用於任何控制器中的任何操作。

return RedirectToAction("Action", "Controller");

當您使用ASP.net MVC時,您可以將其重定向到Account控制器中的LogOn操作

public ActionResult UserMaintenance()
{

  if (User.Identity.IsAuthenticated)
  {
    return View();
  }
  else
  {
    return RedirectToAction("LogOn", "Account");   
  }
}

我會用

http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.redirecttoaction(v=vs.98).aspx

並創建一個新的控制器方法來處理登錄。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM