I want to display of post content with like below url.
http://domainname.com/name-of-post
Please help me to solved this problem with route config
.
This is my codes :
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{param}/{paramAction}",
defaults: new { controller = "Home", action = "Index", param = UrlParameter.Optional, paramAction = UrlParameter.Optional }
);
routes.MapRoute(
name: "ShortUrl",
url: "{PostName}",
defaults: new { controller = "ShortUrl", action = "Post", PostName = UrlParameter.Optional }
);
}
public ActionResult shortaddress(string _postName = "post-name")
{
return RedirectToRoute("ShortUrl", new { postName = _postName });
}
[Route(Name = "ShortUrl")]
public ActionResult Post(string postName)
{
if (string.IsNullOrEmpty(postName))
return RedirectToAction("Index", "Home");
var postData = postsInfo.getPost(postName);
return View(postData);
}