首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> ASP.NET 基礎 >> 關於ASP.NET

ASP.NET MVC 核心教程(七):UrlHelper 產生動態連結與路徑轉換

     編輯:關於ASP.NET

UrlHelper 三大方法

Action - 產生 Action 連結

<%=Url.Action("Index")%>           // 當前 Controller 的 Index
<%=Url.Action("Index", new {id=1})%> // 當前 Controller Index?id=1
<%=Url.Action("Index", "Eice")%>     // Eice Controller 的 Index
<%=Url.Action("Index", "Eice", new {id=1})%> // /eice/index?id=1

Encode - URL 編碼

<%=Url.Encode("中文")%> // 等同 Server.UrlEncode

Content - 相對路徑轉絕對路徑

<%=Url.Content("~/content/site.css")%> // 輸出 /content/site.css

擴充方法

可利用 C# 3.0 擴充方法為 UrlHelper 增加自訂功能。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved