Posts

Showing posts with the label return Redirect()

Difference Between return View(), return Redirect(), return RedirectToAction() And RedirectToRoute() In MVC.

There are different ways of rendering view in MVC. And many of us are confused about them in the beginning stages of our journey as MVC programmers. Here I try my level best to clear up the confusion by explaining the concepts. return View() It tells MVC to generate an HTML template to be displayed and sends it to the browser without making a new request. It does mean that it’s not changing the URL in the browser’s address bar. public  ActionResult Index()   {        return  View();   }   return RedirectToAction() To redirect to a different action which can be in the same or different controller. It tells ASP.NET MVC to respond with a browser to a different action instead of rendering HTML as View() method does. Browser receives this notification to redirect and makes a new request for the new action. return  RedirectToAction(“ActionName”,”ControllerName”); Or this...