ASP.NET MVC 学习心得 (2) - 怎样创建自定义URL Routing

1. 添加Trigger View文件夹, 创建 ChangeTrigger.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

 

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <title>Archive</title>

</asp:Content>

 

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

 

<h2>Archive</h2>

<h2><%= Html.Encode(ViewData["Trigger"])%></h2>

 

</asp:Content>

 

2.添加Engine Controller

public class EngineController : Controller

{

//

// GET: //

 

public ActionResult ChangeTrigger()

{

ViewData["Trigger "] = "Hi from Trigger ";

 

return View();

}

 

}

3.添加新的连接

<li><%= Html.ActionLink("Engine","ChangeTrigger""Engine",)%></li>

4.添加route

routes.MapRoute(

"TriggerChanged",

"Engine/{id}",

new { controller = "Engine", action = "ChangeTrigger", id = "" }

);

posted @ 2009-04-10 17:56  许晓光  阅读(212)  评论(0编辑  收藏  举报