1. Add in global. asax
Routes. maproute ("dbcontent", "{* path}", new {controller = "home"}). routehandler = new catalogroutehandler ();
2. Add the catalogroutehandler class in the Controller folder to inherit from iroutehandler.
Public class catalogroutehandler: iroutehandler
{
Public ihttphandler gethttphandler (requestcontext)
{
String Path = requestcontext. routedata. Values ["path"] as string;
If (Path = NULL)
{
Requestcontext. routedata. Values ["action"] = "Index ";
// Add the path minus the command back in
// Requestcontext. routedata. Values ["path"] = path;
}
Else
{
// Remove trailing slash if there is one
If (path. endswith ("/"))
Path = path. substring (0, path. Length-1 );
If (path! = NULL & path. Contains ("/") // valid path Parameter
{
Int lastindex = path. lastindexof ('/');
If (lastindex> = 0)
{
String commandname = path. substring (lastindex + 1 );
Switch (commandname. toupper ())
{
Case "get": // get the catalog item
Requestcontext. routedata. Values ["action"] = "get ";
// Add the path minus the command back in
Requestcontext. routedata. Values ["path"] = path. substring (0, lastindex );
Break;
Case "delete": // Delete catalog item
Requestcontext. routedata. Values ["action"] = "delete ";
// Add the path minus the command back in
Requestcontext. routedata. Values ["path"] = path. substring (0, lastindex );
Break;
Case "edit": // edit catalog item
Requestcontext. routedata. Values ["action"] = "edit ";
// Add the path minus the command back in
Requestcontext. routedata. Values ["path"] = path. substring (0, lastindex );
Break;
Case "Post": // save catalog item (insert/update)
Requestcontext. routedata. Values ["action"] = "Post ";
// Add the path minus the command back in
Requestcontext. routedata. Values ["path"] = path. substring (0, lastindex );
Break;
Default: // we will allow nothing to act as a get
Requestcontext. routedata. Values ["action"] = "get ";
// Add the path minus the command back in
Requestcontext. routedata. Values ["path"] = path;
Break;
}
}
}
}
Return new mvchandler (requestcontext );
}
}
3. Add get, delete, edit, and post actions to homehandler. CS respectively. And add the corresponding View
Public actionresult get (string path)
{
Return view ();
}
Public actionresult Delete (string path)
{
Return view ();
}
Public actionresult post (string path)
{
Return view ();
}
Public actionresult edit (string path)
{
Return view ();
}
Add home, such as http: // loaclhost: 1124/home/edit
OK.