About the Folders in MVC Web Application in Visual Studio: Part 3

January 26, 2014 , 0 Comments

Controller folder represents the controller for the MVC application created, which have two controller by default i.e. AccountController and HomeController. The functions/methods defined in these classes are called Action results used to specify some rules for the view related to that action.

Every action have its related view responsible for handling user input. Every controller in MVC application have a suffix Controller as the name shown in the default controller folder. Programmer can also create its own controller by adding new from the right click on this folder.

The following action shows two type of login actions, first is for Get action and second is for Post action. When user request for login, get action requests, after submitting with required credentials it requests for post (HttpPost) action (the second one).

        public ActionResult Login(string returnUrl)
            ViewBag.ReturnUrl = returnUrl;
            return View();

        public ActionResult Login(LoginModel model, string returnUrl)
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
                return RedirectToLocal(returnUrl);

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);

There should be a view named Login to make these actions effective. Like this action the AccountController also have Register action, logout action etc.

Subhash Sharma

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google