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);
- }
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
Manas MohapatraPosted Jun 2, 2017, 7:58 AM
Saravanan VPosted Jun 2, 2017, 11:31 AM
As per Microsoft, RedirectToAction Method returns an HTTP 302 response to the browser, which causes the browser to make a GET request to the specified action.
The HttpPostAttribute ( [HttpPost] ) is an implementation of IActionConstraint that will only allow the action to be selected when the HTTP verb is POST.