简体   繁体   中英

ASP.Net MVC: regarding RedirectToAction function

suppose i have two action in controller called login

public ActionResult Login()    
{    
    return View();    
}    

[HttpPost]    
[ValidateAntiForgeryToken]    
public ActionResult Login(UserProfile objUser)     
{    
    if (ModelState.IsValid)     
    {    
    using(DB_Entities db = new DB_Entities())    
    {    
        var obj = db.UserProfiles.Where(a => a.UserName.Equals(objUser.UserName) && a.Password.Equals(objUser.Password)).FirstOrDefault();    
        if (obj != null)    
        {    
        Session["UserID"] = obj.UserId.ToString();    
        Session["UserName"] = obj.UserName.ToString();    
        return RedirectToAction("UserDashBoard");    
        }    
    }    
    }    
    return View(objUser);    
}   

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

You can user above action as a different way like this.

[HttpPost]    
[ValidateAntiForgeryToken]    
public ActionResult Login(UserProfile objUser)     
{    
    // Code;    
}   

[HttpGet]    
[ValidateAntiForgeryToken]    
public ActionResult Login(UserProfile objUser)     
{    
    // Code;    
}  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM