Route Issue

Topics: Customizing Orchard, General, Installing Orchard
May 1, 2013 at 9:48 AM
Edited May 1, 2013 at 10:00 AM
Hi,
I want to create a new link as like below.
blogs/authors/{authorname}.
I have register a new route in Orchard.Blogs module to work the above link. But it is not working. Can you please let me know how to register a new route?
My route is:
new RouteDescriptor {
                                                 Route = new Route(
                                                     "Blogs/authors/{authorname}",
                                                     new RouteValueDictionary {
                                                                                  {"area", "Orchard.Blogs"},
                                                                                  {"controller", "Blog"},
                                                                                  {"action", "Bloggers"}
                                                                              },
                                                     new RouteValueDictionary(),
                                                     new RouteValueDictionary {
                                                                                  {"area", "Orchard.Blogs"}
                                                                              },
                                                     new MvcRouteHandler())
                                             },
Developer
May 1, 2013 at 2:58 PM
Did you also implement an action called "Bloggers" on the "Blog" controller?
Can you show us that action method, including the URL you tried invoking?
May 1, 2013 at 4:07 PM
Edited May 1, 2013 at 4:08 PM
Hi,
Yes. I have created a new action with the name Blogger in blog controller.
The url is localhost/blogs/authors/{authorid} // The default local host url is localhost/blogs
i.e: localhost/blogs/authors/19

public ActionResult Blogger(int ownerid)
    { 
        BloggersModel bc=new BloggersModel();
        var posts = _bc.bloggers(ownerid);


        return View( );
    }
Developer
May 1, 2013 at 4:27 PM
Edited May 1, 2013 at 4:27 PM
Your route token and action arguments need to match. In your route provider, you are using {authorname}.
In your previous post, you are saying it is {authorid}.
In your action, you are using {ownerid}.

To have your route match with your action, your action needs to accept an argument that has the same name as your route token, e.g. "authored".
May 1, 2013 at 4:53 PM
Hi,
The author id is dynamic. So i have used my route as localhost/blogs/authors/{ownerid}

I have changed the route with ownerid. Even the link is not working. Can you please let me know how to resolve it?

Route.CS code is as follows?

using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using Orchard.Blogs.Routing;
using Orchard.Mvc.Routes;

namespace Orchard.Blogs {
public class Routes : IRouteProvider {
    private readonly IArchiveConstraint _archiveConstraint;
    private readonly IRsdConstraint _rsdConstraint;

    public Routes(
        IArchiveConstraint archiveConstraint,
        IRsdConstraint rsdConstraint) {
        _archiveConstraint = archiveConstraint;
        _rsdConstraint = rsdConstraint;
    }

    public void GetRoutes(ICollection<RouteDescriptor> routes) {
        foreach (var routeDescriptor in GetRoutes())
            routes.Add(routeDescriptor);
    }

    public IEnumerable<RouteDescriptor> GetRoutes() {
        return new[] {
                         new RouteDescriptor {
                                                 Route = new Route(
                                                     "Admin/Blogs/Create",
                                                     new RouteValueDictionary {
                                                                                  {"area", "Orchard.Blogs"},
                                                                                  {"controller", "BlogAdmin"},
                                                                                  {"action", "Create"}
                                                                              },
                                                     new RouteValueDictionary(),
                                                     new RouteValueDictionary {
                                                                                  {"area", "Orchard.Blogs"}
                                                                              },
                                                     new MvcRouteHandler())

                                             },

                         new RouteDescriptor {
                                                 Route = new Route(
                                                     "Admin/Blogs/{blogId}/Edit",
                                                     new RouteValueDictionary {
                                                                                  {"area", "Orchard.Blogs"},
                                                                                  {"controller", "BlogAdmin"},
                                                                                  {"action", "Edit"}
                                                                              },
                                                     new RouteValueDictionary (),
                                                     new RouteValueDictionary {
                                                                                  {"area", "Orchard.Blogs"}
                                                                              },
                                                     new MvcRouteHandler())
                                             },
                         new RouteDescriptor {
                                                 Route = new Route(
                                                     "Admin/Blogs/{blogId}/Remove",
                                                     new RouteValueDictionary {
                                                                                  {"area", "Orchard.Blogs"},
                                                                                  {"controller", "BlogAdmin"},
                                                                                  {"action", "Remove"}
                                                                              },
                                                     new RouteValueDictionary (),
                                                     new RouteValueDictionary {
                                                                                  {"area", "Orchard.Blogs"}
                                                                              },
                                                     new MvcRouteHandler())
                                             },
                         new RouteDescriptor {
                                                 Route = new Route(
                                                     "Blogs/auhors/ownerid",
                                                     new RouteValueDictionary {
                                                                                  {"area", "Orchard.Blogs"},
                                                                                  {"controller", "Blog"},
                                                                                  {"action", "Blogger"}
                                                                              },
                                                     new RouteValueDictionary (),
                                                     new RouteValueDictionary {
                                                                                  {"area", "Orchard.Blogs"}
                                                                              },
                                                     new MvcRouteHandler())
                                             },


                         new RouteDescriptor {
                                                 Route = new Route(
                                                     "Admin/Blogs/{blogId}/Posts/Create",
                                                     new RouteValueDictionary {
                                                                                  {"area", "Orchard.Blogs"},
                                                                                  {"controller", "BlogPostAdmin"},
                                                                                  {"action", "Create"}
                                                                              },
                                                     new RouteValueDictionary (),
                                                     new RouteValueDictionary {
                                                                                  {"area", "Orchard.Blogs"}
                                                                              },
                                                     new MvcRouteHandler())
                                             },
                         new RouteDescriptor {
                                                 Route = new Route(
                                                     "Admin/Blogs/{blogId}/Posts/{postId}/Edit",
                                                     new RouteValueDictionary {
                                                                                  {"area", "Orchard.Blogs"},
                                                                                  {"controller", "BlogPostAdmin"},
                                                                                  {"action", "Edit"}
                                                                              },
                                                     new RouteValueDictionary (),
                                                     new RouteValueDictionary {
                                                                                  {"area", "Orchard.Blogs"}
                                                                              },
                                                     new MvcRouteHandler())
                                             },
                         new RouteDescriptor {
                                                 Route = new Route(
                                                     "Admin/Blogs/{blogId}/Posts/{postId}/Delete",
                                                     new RouteValueDictionary {
                                                                                  {"area", "Orchard.Blogs"},
                                                                                  {"controller", "BlogPostAdmin"},
                                                                                  {"action", "Delete"}
                                                                              },
                                                     new RouteValueDictionary (),
                                                     new RouteValueDictionary {
                                                                                  {"area", "Orchard.Blogs"}
                                                                              },
                                                     new MvcRouteHandler())
                                             },
                         new RouteDescriptor {
                                                 Route = new Route(
                                                     "Admin/Blogs/{blogId}/Posts/{postId}/Publish",
Developer
May 1, 2013 at 5:34 PM
Edited May 1, 2013 at 5:35 PM
nsathyacse wrote:
Hi,
The author id is dynamic. So i have used my route as localhost/blogs/authors/{ownerid}
According to your code snippet, it is not. Instead, you are using this:
new Route("Blogs/auhors/ownerid", ...
Do you see it?
May 2, 2013 at 5:06 AM
Hi,
I have tried both. No use. Both are not working.
new Route("Blogs/auhors/ownerid",...
new Route("Blogs/auhors/{ownerid}

Can you please let me know how to fix this issue.