Lightweight. NET MVC---QMVC

Source: Internet
Author: User

asp.net! The word represents a word fat! because he is always tied too much to too many classes, too many different features! You may use, if you decompile or read their open source source code, you will be like in the sea can not find the direction? Whether it's Web form or MVC.

Qmvc as the name implies! q=quick! He worships flexible, simple, fast! If you like these features, read on, and I'll introduce you to a new. NET MVC framework whose name is Qmvc.

What is QMVC

QMVC is the high-performance MVC framework, Q is the abbreviation for quick, MVC is the abbreviation of model, Controller and view respectively. QMVC, developed using the C # programming language, uses the Microsoft. NET Framework 4.5 class library for B/S structural project development. The author of the Qmvc Project, Guoxiu, is a Buddhist believer in China, who once said that this project is free and open source, because he says that he is good at doing things and advocating the purpose of dharma.
Like the standard MVC, QMVC is composed of controllers, models, and views that are used to handle program logic, such as writing to a database, uploading files, and so on, when the controller loads the data, encapsulates the data into a model class, and the view displays the page content through the data in the model. This process of thinking more clearly, the artist can be more simple to modify the display layer, because the program code and template Independent.

How to download Qmvc

QMVC official website: http://www.wuxiu.org/Download the source code, after decompression, you can see three items, Wuxiu. QMVC, Wuxiu. Qmvc. APPS. DEMO and Wuxiu.QMVC.DEMO. Which Wuxiu. The QMVC project is the core class library of QMVC to support the operation of the MVC framework. Wuxiu. Qmvc. Demo is a sample project for QMVC, which demonstrates the basic functions of QMVC. Wuxiu. Qmvc. APPS. Demo Project for demo QMVC app sample code.

QMVC Source

The namespace is introduced first, and all namespaces are Wuxiu. Qmvc begins, where Wuxiu is the pinyin of the Chinese author's name. Which Wuxiu. Qmvc. All relevant QMVC application-related class library supporters are stored under the apps namespace, most of which inherit from Wuxiu. The base class implementation in QMVC. Tbz. Qmvc. The router namespace mainly contains the code that QMVC the URL routing function, which is used to handle the parsing function of the URL address. Wuxiu. Qmvc. APPS. The router namespace is used to handle the URL routing feature in Qmvc app mode.

Start creating a QMVC project

1. Open Visual Studio and create a new ASP. NET Blank project based on the framework4.5, with the project name "Myqmvc",

2, add Reference tbz. QMVC.dll,: (http://www.wuxiu.org/downloads.html), version tbz.qmvc.1.0,

3. Create a new Global.asax file and add the code in the Application_Start and Application_BeginRequest events:

        protected void Application_Start (object  sender, EventArgs e)        {            Routermanager.registerdefaultrouter (  This . GetType ());        }         protected void Application_BeginRequest (object  sender, EventArgs e)        {            Wuxiu. Qmvc. Qmvccore.page_beginrequest (new httpcontextwrapper (this. Context));        }

4. Create the folder "Controllers, Models, defaultviews" In Solution Explorer and create a folder in Defaultviews home,

Description: The default view in Defaultviews, the user can also create blueviews, redviews and other themes of the theme, you can flexibly through the QMVC provided by the theme features. The home in Defaultviews to the HomeController in controllers, which is used to hold the view in HomeController.

5. Open the project with the "Web. config" file in the directory and add the System.webserver node under the configuration item:

<runallmanagedmodulesforallrequests= "true"/>

Description: This means telling IIS to give all the requests to the module program, which means that all requests are given to ASP.

Then add the contents of the compilation node under the system.web node:

<Assemblies>        <AddAssembly= "System.Web.WebPages.Razor2, version=9.0.0.1, Culture=neutral, Publickeytoken=14679ed9c77dd5f5" />        <AddAssembly= "System.Web.WebPages2, version=9.0.0.1, Culture=neutral, Publickeytoken=14679ed9c77dd5f5" />        <AddAssembly= "System.Web.Razor2, version=9.0.0.1, Culture=neutral, Publickeytoken=14679ed9c77dd5f5" />      </Assemblies>      <buildproviders>        <Removeextension= ". cshtml"/>        <Addextension= ". cshtml"type= "System.Web.WebPages.Razor.RazorBuildProvider, System.Web.WebPages.Razor2"/>      </buildproviders>    </compilation>

6. Create a new Web. config file under the Defaultviews directory and add the following code under the configuration node:

    <sectiongroupname= "System.web.webPages.razor"type= "System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor2">      < Sectionname= "Host"type= "System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor2"requirepermission= "false" />      < Sectionname= "pages"type= "System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor2"requirepermission= "false" />    </sectiongroup>  </configsections>  <System.web.webPages.razor>    <pagesPageBaseType= "Wuxiu." Qmvc. Mvcrzorpagebase ">      <Namespaces>        <Addnamespace= "Wuxiu." Qmvc " />      </Namespaces>    </pages>  </System.web.webPages.razor>

Description, this code tells the ASP. Razor template engine to QMVC to compile, improper configuration will cause razor engine browsing error.

7, to here, a QMVC project framework is completed, the following implementation of a simple QMVC program. Create the next class file "Home_index.cs" under the models directory, with the following code:

using  System;  namespace  Myqmvc. Models {    public class  home_indexmodel    {        public string<  /c11>getset;}    }}

Create a ComeController.cs class file under the Contrllers directory (note, you must end with a controller), the code is as follows:

usingSystem;usingsystem.web;usingWuxiu. QMVC;namespaceMyqmvc. controllers{ Public classHomecontroller:controllerbase { PublicViewResult Index () {Models.home_indexmodel model=NewModels.home_indexmodel (); Model. MSG="Hello world!"; returnView (model); }    }}

8. Create a new view of the next index.cshtml in Defaultviews\home,

The code is as follows:

@{myqmvc.  Models.home_indexmodel model = model;} <!DOCTYPE HTML>    <HTMLxmlns= "http://www.w3.org/1999/xhtml">    <Head>        <title>QMVC Web page</title>    </Head>    <Body>        <H1>QMVC is runing!</H1>        <Div>Msg: @model. MSG</Div>    </Body>    </HTML>

9, close index.cshtml, press F5 Run, see the effect!

Respect the original, reprint please indicate the source ^_^



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.