Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>ok, I examined <a href="http://www.asp.net/(S(pdfrohu0ajmwt445fanvj2r3))/learn/mvc/tutorial-05-cs.aspx" rel="noreferrer">Walther's tutorial</a> and got a basic MVC site running. </p> <p>The files required were: </p> <pre><code>Global.asax App_Code\Global.asax.cs App_Code\Controller.cs Views\HelloWorld\Sample.aspx web.config </code></pre> <p>That's it. </p> <p>Inside the Global.asax, I provide this boilerplate:</p> <pre><code>&lt;%@ Application Inherits="MvcApplication1.MvcApplication" Language="C#" %&gt; </code></pre> <p>And that <code>MvcApplication</code> class is defined in a module called Global.asax.cs which must be placed into the App_Code directory. The contents are like this: </p> <pre><code>using System.Web.Mvc; using System.Web.Routing; public class MvcApplication : System.Web.HttpApplication { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{arg}", // URL with parameters new { // Parameter defaults controller = "HelloWorld", action = "Index", arg = "" } ); } protected void Application_Start() { RegisterRoutes(RouteTable.Routes); } } </code></pre> <p>The Controller.cs provides the logic to handle the various requests. In this simple example, the controller class is like this: </p> <pre><code>using System.Web.Mvc; namespace MvcApplication1.Controllers { public class HelloWorldController : Controller { public string Index() { return "Hmmmmm...."; // coerced to ActionResult } public ActionResult English() { return Content("&lt;h2&gt;Hi!&lt;/h2&gt;"); } public ActionResult Italiano() { return Content("&lt;h2&gt;Ciao!&lt;/h2&gt;"); } public ViewResult Sample() { return View(); // requires \Views\HelloWorld\Sample.aspx } } } </code></pre> <p>The Controller class must be named <code>XxxxxController</code>, where the Xxxxx portion defines the segment in the URL path. For a controller called <code>HelloWorldController</code>, the URL path segment is <code>HelloWorld</code>. Each public method in the Controller class is an <em>action</em>; the method is called when that method name is included in another segment in the url path . So for the above controller, these URLs would result in invoking the various methods:</p> <ul> <li>http:/ /server/root/HelloWorld (the default "action")</li> <li>http:/ /server/root/HelloWorld/Index (same as above)</li> <li>http:/ /server/root/HelloWorld/English</li> <li>http:/ /server/root/HelloWorld/Italiano</li> <li>http:/ /server/root/HelloWorld/Sample (a view, implemented as Sample.aspx)</li> </ul> <p>Each method returns an <em>Action result</em>, one of the following: View (aspx page), Redirect, Empty, File (various options), Json, Content (arbitrary text), and Javascript.</p> <p>The View pages, such as Sample.aspx in this case, must derive from <code>System.Web.Mvc.ViewPage</code>.</p> <pre><code>&lt;%@ Page Language="C#" Debug="true" Trace="false" Inherits="System.Web.Mvc.ViewPage" %&gt; </code></pre> <p>That's it! Dropping the above content into an IIS vdir gives me a working ASPNET MVC site.</p> <p>(Well, I also need the web.config file, which has 8k of configuration in it. <a href="http://cheeso.members.winisp.net/srcview.aspx?dir=Mvc.HelloWorld&amp;file=web.config.txt" rel="noreferrer">All this source code and configuration is available to browse or download.</a>)</p> <p>And then I can add other static content: js, css, images and whatever else I like.</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