NANCYFX Cross-Platform Development Summary (ii) Hello World

Source: Internet
Author: User

As a rule, start by building a simple Hello Word project as a course development

  • Create a new, basic ASP. NET WEB Application project with Visual Studio, named website. Mono's currently compatible. NET version is 4.5, so use the. NET Framework 4.5 here
  • Install the following development packages with NuGet
      • Nancy
      • Nancy.Viewengines.Razor: Using the Razor view engine
      • Microsoft.Owin.Host.SystemWeb: Using katana as a web host for Owin
      • Nancy.owin
  • The
  • mimics the standard ASP. NET MVC project to build the directory so that it looks more like a. Nets MVC program. Add two MVC View page (Razor) files, and the page file code is similar to the ASP.
    • _viewstart.cshtml code
       @{Layout = "shared/_layout.cshtml";}  
    • _layout.cshtml code

      <! DOCTYPE Html>,

           <title> @ViewBag. Title</title>

          <meta charset= " Utf-8 "/>

          <meta name=" viewport "content=" Width=device-width, initial-scale=1.0,

      <body>,

               @RenderBody ()

          </div>

      </body>

        

       

  • In the root directory, create a new Owin Startup class with the following code
     Public class startup{        publicvoid  Configuration (Iappbuilder app)        {            app. Usenancy ();        }}
  • Add Class Homeviewmodel in Models
     Public class homeviewmodel{        publicstringgetset;}
  • Controller Add Class Indexcontroller, inherited from Nancymodule, this class is the director. Unlike the ASP. NET Webapi, Nancy defines Get,post,put in the constructor, Delete routing path and method.
    usingNancy;usingnancy.security;usingWebsite.models; Public classindexcontroller:nancymodule{ PublicIndexcontroller () {get["/"] = _ ~ =Index (); get["/index"] = _ ~ =Index (); }       Private DynamicIndex () { This. Viewbag.title ="Hello Word"; varModel =NewHomeviewmodel () {Name="Helle word,carl!"            }; returnview["Home/index", model]; }}
  • Add the index.cshtml view file under home to display the model's Name property value on the page
    <div>    @Model .name</div>
  • Configuring Webconfig, configuring support for Katana web hosting
    <!-katana-asp.net Owin Host supports--><appsettings>    <add key= "owin:handleallrequests" value= "true"/ ></appSettings>

      

Nancyfx Cross-platform Development Summary (ii) Hello World

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.