zoukankan      html  css  js  c++  java
  • 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

    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

  • 相关阅读:
    C# WebClient 使用http免费代理
    C#中给WebClient添加代理Proxy
    浅谈C#实现Web代理服务器的几大步骤
    Visual Studio 2017各版本安装包离线下载、安装全解析
    C# HttpClient, 使用C#操作Web
    ROS学习之 tab补全错误
    ROS学习之group标签
    ROS学习之CMakeLists.txt
    ROS学习之包的概念
    ROS学习之package.xml
  • 原文地址:https://www.cnblogs.com/zoumin123/p/5256537.html
Copyright © 2011-2022 走看看