Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Model</strong> - Is a data structure that represents some kind of object (usually one). It's purpose is to read, write and manage the access to the underlying object with the aim to persist application state.</p> <p><strong>View</strong> - Is the components that are used to display a visual interface to the user, perhaps using a model. It might be a simple table or a complex combination into a full web page.</p> <p><strong>Controller</strong> - Is the user driven application logic layer the sits between views and models. It handlers user interaction, loads models, and sends views to the user. It determines what model is sent to the view depending on user requests.</p> <p>The overall folder structure for an application might look like this.</p> <pre><code>&gt;&gt; Website &gt;&gt; Controllers &gt;&gt; Models &gt;&gt; Views </code></pre> <p>In C# MVC each controller must have the suffix <code>Controller</code> in the name, they must extend Controller class and have a folder of the name prefix (without the <code>Controller</code>) in the views folder. This folder will then contain all the views related to particular actions on the controller.</p> <p>Controllers can contain any number of actions defined as public functions. By default when returning a result from a controller action the name of the view must correspond with the name of the action. However you can also specify a view by name. When loading a view from a controller, it is possible to send an object as a model to the view and there by generate it's content.</p> <p>Controllers can load any model and are not restricted in any way.</p> <p>An <code>Account</code> controller defined as below with an action <code>Login</code>. The controller is placed in a <code>AccountController.cs</code> file in the <code>/Controllers</code> folder, and any views for this controller (<code>Login</code> in this instance with filename <code>Login.cshtml</code>) are placed in the <code>/Views/Account</code> folder.</p> <p>Note: The naming convention has to be right as the names are used between the controllers and views to link the data.</p> <pre><code>public class AccountController : Controller { public ActionResult Login(string returnUrl) { if (User.Identity.IsAuthenticated) { return RedirectToAction("Index","Site"); } return View("Login", new LogOnModel()); } } </code></pre> <p>would be accessible via <code>http://www.mysite.com/Account/Login</code>. If the user is authenticated, the controller will redirect to the main site controller, if the user is not logged in then they are shown the <code>Login</code> view which loads data from the <code>LogOnModel</code> specified.</p> <p>This is really just touching the surface of what is possible. Read some online information on some excellent articles by ScottGu which go into much more depth and talk you through how to use MVC.</p> <p><a href="http://weblogs.asp.net/scottgu/archive/2007/10/14/asp-net-mvc-framework.aspx">ASP.NET MVC Framework Overview</a></p> <p><a href="http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx">ASP.NET MVC Framework How To - Part 1</a> // <a href="http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx">Part 2</a> // <a href="http://weblogs.asp.net/scottgu/archive/2007/12/06/asp-net-mvc-framework-part-3-passing-viewdata-from-controllers-to-views.aspx">Part 3</a> // <a href="http://weblogs.asp.net/scottgu/archive/2007/12/09/asp-net-mvc-framework-part-4-handling-form-edit-and-post-scenarios.aspx">Part 4</a></p> <p>Note : These articles are slightly outdated as they were written for MVC version 1 back in 2007, but the concepts of how the Models, Views and Controller interact still apply.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload