Hi Guys
I have a issue that they users here want urls like http://host/Post/PostTitle
Is this possible?
As your not passing in the action?
regards
Hi Guys
I have a issue that they users here want urls like http://host/Post/PostTitle
Is this possible?
As your not passing in the action?
regards
Sure, you just make an appropriate route. It depends very much on other routes you have in your map, but this shoult work in almost any situation. Put it before the default route, though.
routes.MapRoute(
"Login",
"Page/{id}",
new { controller = "Page", action = "index", id = "" }
);
You can infer the action by setting up appropriate URL Routing schemes
This msdn atricle goes in to great deatil how to set up default values.
AFAIK, URL Rewriting feature is only introduced in IIS 7. Read this blog for more details on that.
Palantir is right, you can make a route like this:
routes.MapRoute(
"Posts", // route name
"Post/{PostTitle}",
new { controller = "Post", action = "Index" }
);
And then , in your PostController, you should create action as follows:
public ActionResult Index(string PostTitle)
{
...
}
Try changing your PostController to this (for testing purposes).
public class PostController : Controller
{
public string Index(string postTitle)
{
return postTitle;
}
}
And your route defined as
routes.MapRoute(
"Posts", // route name
"Post/{PostTitle}",
new { controller = "Post", action = "Index" }
);