tri_inn

tri_inn

  • NA
  • 1.2k
  • 232.4k

ASP.Net MVC: regarding RedirectToAction function

Jun 2 2017 7:26 AM
suppose i have two action in controller called login
 
  1. public ActionResult Login()    
  2. {    
  3.     return View();    
  4. }    
  5.     
  6. [HttpPost]    
  7. [ValidateAntiForgeryToken]    
  8. public ActionResult Login(UserProfile objUser)     
  9. {    
  10.     if (ModelState.IsValid)     
  11.     {    
  12.     using(DB_Entities db = new DB_Entities())    
  13.     {    
  14.         var obj = db.UserProfiles.Where(a => a.UserName.Equals(objUser.UserName) && a.Password.Equals(objUser.Password)).FirstOrDefault();    
  15.         if (obj != null)    
  16.         {    
  17.         Session["UserID"] = obj.UserId.ToString();    
  18.         Session["UserName"] = obj.UserName.ToString();    
  19.         return RedirectToAction("UserDashBoard");    
  20.         }    
  21.     }    
  22.     }    
  23.     return View(objUser);    
  24. }   
 when we write return RedirectToAction("Login");  then how asp.net mvc understand that we are thinking about login function which uisng get http verb login not post http verb login ?
anyone can explian it ?
 
how we can redirect to action which is based on post http verb ?
what will be the syntax if we need to redirect to action with http verb if we use RedirectToAction function  ?
 
thanks

Answers (2)