你的位置:首页 > 软件开发 > ASP.net > Orchard helloworld

Orchard helloworld

发布时间:2016-03-09 02:00:06
原文链接:http://www.orchardproject.net/docs/Building-a-hello-world-module.ashx命令行语法:http://www.cnblogs.com/esshs/archive/2011/06/09/2076129.html ...

原文链接: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

Orchard helloworldOrchard helloworld
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())        }      };    }  }}

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

原标题:Orchard helloworld

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录