asp.net mvc case Tutorial (based on asp.net mvc beta)--second: first page

Source: Internet
Author: User

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}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.