Using only ASP.NET Web Pages framework without ASP.NET MVC, it is possible to do MVC, because the ASP.NET Web Pages framework has already provided fundamental infrastructure for routing and view invocation. Using the infrastructure, MVC in Rabbit it Framework can be done in a simple way.

Using cshtml as Controller

Thanks to ASP.NET Web Pages’ built-in magic routing, a request like http://…/pages/a/b/c/d is routed to /pages.cshtml.

URLs list below are all routed to pages.cshtml. Therefore the pages.cshtml can be used as controller, if made it inherit from Rabbit.MvcController.

http://../pages
http://../pages/about
http://../pages/edit/about
http://../pages/delete/about
http://../pages/save (post)

By adding two custom .NET attributes, Get and Post, the controller looks like below. The URLs are routed to different functions.

@using Rabbit;
@inherits MvcController

@functions {

    [Get("/")]
    public virtual void Default()
    {
    }
 
    [Get("/*")]
    public virtual void Get()
    {
    }
 
    [Get("Edit")]
    public virtual void Edit()
    {
    }

    [Get("Delete")]
    public virtual void Delete()
    {
    }

    [Post("Save")]
    public virtual void Save()
    {
    }
}

Views

The View function in controller invokes view, which also pushes model data to the view. To access the model in the view, use the dynamic property called Page.

The views are located using the convention: ~/{controller}{action}.cshtml.

Differences Compare to ASP.NET MVC

Rabbit MVC is lightweight. There is no global routing. The cshtml files serve as the controller.

See the sample page Demo_Mvc.cshtml from the sample site.

Last edited Jul 23, 2011 at 8:38 PM by yysun, version 5

Comments

No comments yet.