欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ASP.NET MVC - 控制器

為了學習 ASP.NET MVC,我們將構建一個 Internet 應用程序。

部分 4:添加控制器。

Controllers 文件夾

Controllers 文件夾包含負責處理用戶輸入和響應的控制器類。

MVC 要求所有控制器的名稱必須以 "Controller" 結尾。

在我們的例子中,Visual Web Developer 已創(chuàng)建以下文件:HomeController.cs(用于首頁和關于頁面)和 AccountController.cs (用于登錄頁面):

web 服務器通常會將進入的 URL 請求直接映射到服務器上的磁盤文件。例如:某個 URL 請求(比如 "http://www.dbjr.com.cn/index.asp")將映射到服務器根目錄上的文件 "index.asp"。

MVC 框架的映射方式有所不同。MVC 將 URL 映射到方法。這些方法在類中被稱為“控制器”。

控制器負責處理進入的請求、處理輸入、保存數(shù)據(jù)、并把響應發(fā)送回客戶端。

Home 控制器

我們應用程序中的控制器文件 HomeController.cs,定義了兩個控件 IndexAbout。

把 HomeController.cs 文件的內(nèi)容替換為:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcDemo.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{return View();}

public ActionResult About()
{return View();}
}
}

Controller 視圖

Views 文件夾中的文件 Index.cshtmlAbout.cshtml 定義了控制器中的 ActionResult 視圖 Index() 和 About()。