星空网 > 软件开发 > ASP.net

Orchard helloworld

原文链接: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())        }      };    }  }}

View Code

4. 创建控制器

  Controllers的文件夹(如果没有则创建一个),在这个文件夹中创建HomeController.cs文件

Orchard helloworldOrchard helloworld
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





原标题:Orchard helloworld

关键词:

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

跨境猫:https://www.goluckyvip.com/tag/36826.html
跨境贸易电商:https://www.goluckyvip.com/tag/36827.html
跨境贸易电子商务服务:https://www.goluckyvip.com/tag/36829.html
跨境快车道:https://www.goluckyvip.com/tag/3683.html
跨境贸易电子商务网:https://www.goluckyvip.com/tag/36832.html
跨境贸易海外仓:https://www.goluckyvip.com/tag/36833.html
深圳西乡三月三北帝庙会的千岁盆菜多少钱:https://www.vstour.cn/a/365180.html
TikTok SEO:TikTok会取代谷歌吗?:https://www.kjdsnews.com/a/1836538.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流