Share via


Add a Main Web Page to the Application

[This content is no longer valid. For the latest information on "M", "Quadrant", SQL Server Modeling Services, and the Repository, see the Model Citizen blog.]

This is the fifth step in the Getting Started with SQL Server Modeling CTP and Visual Studio 2010 tutorial. The preceding step is Develop Using Generated Entity Framework Classes. The following step is Generate "M" from an Existing Database. In this topic you will build a main Web page for the application that shows the upcoming dinners. The FindUpcomingDinners method that you defined previously generates the rows that you will display in the Web page.

Build the main view for DinnersController

  1. In the DinnersController class, right click the Index method and select Add View.

    Shows adding a view to the controller.

  2. In the Add View dialog box, select Create a strongly-typed view, select MiniNerdDinner.Dinner in the View data class box, and then select List in the View content box. Click Add.

    Shows Add View dialog box.

  3. In the DinnersController class, modify the Index method to contain the following code. This connects the Index controller action to the strongly-typed view that you just created.

    public ActionResult Index()
            {
                var dinners = FindUpcomingDinners();
                return View("Index", dinners);
            }
    
  4. In Solution Explorer, double-click Global.asax and modify the RegisterRoutes method to contain the following code. Note the change to the last argument to MapRoute, which makes our new controller the default for the application.

    public static void RegisterRoutes(RouteCollection routes)
            {
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
                routes.MapRoute(
                    "Default",                                              // Route name
                    "{controller}/{action}/{id}",                           // URL with parameters
                    new { controller = "Dinners", action = "Index", id = "" }  // Parameter defaults
                );
            }
    

Run the application

  1. In Solution Explorer, right-click MiniNerdDinner.Tests and select Set as Startup Project.

  2. Press F5 to start the application. The ASP.NET Development Server icon appears in the system tray.

    Tip

    The precise port portion of the URL may be different on your computer.

    SysTray shows deployment information.

  3. Right-click the icon and select Open in Web Browser.

    Shows the deployment option from the SysTray.

  4. A browser window appears. The main page should look as follows. Note that the Web page shows the instance data that you authored by using “M”.

    Tip

    The precise port portion of the URL may be different on your computer.

    Shows the running application.

See Also

Concepts

Getting Started with SQL Server Modeling CTP and Visual Studio 2010