Let the first page run
Now, let's implement the first page of the bulletin system--the homepage. It's very simple, it only includes a list of all bulletin classifications, and each list item is a hyperlink. Where the classified data is obtained with our mock component. After the implementation of the interface is as follows:
Before we begin, we have to delete a few things. Because by default an MVC project is built with several sample pages in it, all we have to do is:
1. Delete all files under the Controllers folder.
2. Delete all files except the shared folder and Web.config in the Views folder, and then delete the files in the shared folder.
Once you've completed these steps, you're ready to start implementing the first page.
Implement controller
Create a new file under the Controllers folder, type "MVC Controller Class", and name HomeController.cs. This is a controller class. Then we encode it, and the specific code is as follows:
HomeController.cs:
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.Mvc;
6using System.Web.Mvc.Ajax;
7using MVCDemo.Models;
8using MVCDemo.Models.Interfaces;
9using MVCDemo.Models.Entities;
10
11namespace MVCDemo.Controllers
12{
13 public class HomeController : Controller
14 {
15 public ActionResult Index()
16 {
17 ICategoryService cServ = ServiceBuilder.BuildCategoryService();
18 ViewData["Categories"] = cServ.GetAll();
19 return View("Index");
20 }
21 }
22}