Orchard helloworld, orchardhelloworld

Source: Internet
Author: User

Orchard helloworld, orchardhelloworld

Link: http://www.orchardproject.net/docs/Building-a-hello-world-module.ashx

Command Line Syntax: http://www.cnblogs.com/esshs/archive/2011/06/09/2076129.html

Enable the automatic generation of hardware hard code: orchard> feature enable Orchard. CodeGeneration

1. Generate the module structure

Run the following command to create the HelloWorld module:

Startup module command: codegen module HelloWorld

(Orchard actually creates a VS Project (HelloWorld. csproj) for us, so we can use the VS development module)

2. modify the configuration

Modify: module.txt

3. Add a route

Create a Route file Route. cs in the HelloWorld root directory

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. Create a controller

Controllers folder (if not, create one). In this folder, create the HomeController. cs File

Using System. web. mvc; using Orchard. themes; namespace HelloWorld. controllers {[Themed] public class HomeController: Controller {public ActionResult Index () {return View ("HelloWorld ");}}}View Code

5. Create a view

Create a sub-folder named Home in the Views folder of the module root directory. In the Views/Home folder, create a View File named HelloWorld. cshtml and enter the following content:

6. Update the project file

Open the HelloWorld. csproj file and add:

<ItemGroup>
  <Compile Include="Routes.cs"/>
  <Compile Include="Controllers/HomeController.cs"/>
ItemGroup>

Add the following to make the View File included in the project:

  <Content Include="Views/HelloWorld.cshtml" />

7. Activation Module

Activation module command: feature enable HelloWorld

8. Modules

Http: /localhost: 30321/OrchardLocal/HelloWorld

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.