Programming - ASP.NET MVC Example
The original Microsoft example is available here also.
To run the following sample, you will need the following
tools.
ASP.NET and URL rules and routes. REST
implementation.
A rule allows the user to define how a web resource should
be looked up. Think of them as aliases. They are the centre
piece to the diea of a REST service.
They are added to the RouteTable in the global.asx file.
RouteTable.Routes.Add(new Route
{
and Url = "[controller]/[action]/[id]",
and Defaults = new { action = "Index", id = (string)null },
and RouteHandler = typeof(MvcRouteHandler)
});
The next step is to define the model. This is the data that
you will be using.
You can use teh Microsoft example of the Northwinds DB and
the Entity Framework OR, you can sue ObjectMapper and
nHibernate to spit out POCOs that can be used by ASP.NET
MVC.
We then add the controller. Think of this like the logic to
your code. The published interface. This is where the hard grft
happens. You will create colections and return dataandin
this tier.
The view is the presentation layer. This is your usually
ASP.NET Masterpage and controls.
MVC decouples the ;ayers, but you need to tel the page what
data it is viewing. This is done by some generic magic.
public partial class MyPage: ViewPage< List<MyDataClass> >
{
}
In the ASPX page, you can now simple output the view data by
accessing the ViewData object which is part of the ViewPage
class.This is the simplest example. As you can see, the logical
levels have been seperated and testing becomes a doddle. Check
the Microsoft example at the top of this page for a more
thorough example.
and
and
and
and