原文鏈接:http://www.orchardproject.net/docs/Building-a-hello-world-module.ashx 命令行語法:http://www.cnblogs.com/esshs/archive/2011/06/09/2076129.html 啟用Oracha
原文鏈接:http://www.orchardproject.net/docs/Building-a-hello-world-module.ashx
命令行語法:http://www.cnblogs.com/esshs/archive/2011/06/09/2076129.html
啟用Orachard的代碼自動生成功能:orchard> feature enable Orchard.CodeGeneration
1. 生成模塊結構
輸入以下命令來創建HelloWorld模塊:
啟動模塊命令:codegen module HelloWorld
(Orchard實際上是為我們創建了一個VS項目(HelloWorld.csproj),這樣既可以使用VS開發模塊)
2. 修改清單
修改: module.txt
3. 添加路由
HelloWorld根目錄下 新建 路由文件Route.cs
using System.Collections.Generic; using System.Web.Mvc; using System.Web.Routing; using Orchard.Mvc.Routes; namespace HelloWorld { public class Routes : IRouteProvider { public void GetRoutes(ICollection<RouteDescriptor> routes) { foreach (var routeDescriptor in GetRoutes()) routes.Add(routeDescriptor); } public IEnumerable<RouteDescriptor> GetRoutes() { return new[] { new RouteDescriptor { Priority = 5, Route = new Route( "HelloWorld", // this is the name of the page url new RouteValueDictionary { {"area", "HelloWorld"}, // this is the name of your module {"controller", "Home"}, {"action", "Index"} }, new RouteValueDictionary(), new RouteValueDictionary { {"area", "HelloWorld"} // this is the name of your module }, new MvcRouteHandler()) } }; } } }View Code
4. 創建控制器
Controllers的文件夾(如果沒有則創建一個),在這個文件夾中創建HomeController.cs文件
using System.Web.Mvc; using Orchard.Themes; namespace HelloWorld.Controllers { [Themed] public class HomeController : Controller { public ActionResult Index() { return View("HelloWorld"); } } }View Code
5. 創建視圖
模塊根目錄的Views文件夾中創建一個名為Home的子文件夾。在Views/Home文件夾中,創建名為HelloWorld.cshtml的視圖文件,並輸入以下內容:
<h2>@T("Hello World!")h2>
6. 更新項目文件
打開HelloWorld.csproj文件 添加:
<ItemGroup>
<Compile Include="Routes.cs"/>
<Compile Include="Controllers/HomeController.cs"/>
ItemGroup>
還要添加下麵這條,讓視圖文件也包含在項目中:
<Content Include="Views/HelloWorld.cshtml" />
7. 激活模塊
激活模塊命令:feature enable HelloWorld
8. 使用模塊
http://localhost:30321/OrchardLocal/HelloWorld