Say I have my model like so:
public class Book
{
public String ID { get; set; }
public String Title { get; set; }
}
public class Author
{
public String ID { get; set; }
public String Name { get; set; }
}
And my RouteConfig defined like so:
routes.MapRoute(
name: "Book",
url: "Book/{id}",
defaults: new { controller = "Books", action = "Book" }
);
routes.MapRoute(
name: "Author",
url: "Author/{id}",
defaults: new { controller = "Authors", action = "Author" }
);
Now, I want to add a slug to the end of each Author
route and each Book
route. So for example:
/Author/1 => /Author/1/sir-arthur-conan-doyle
/Book/1 => /Book/1/sherlock-holmes
All of my ActionLinks and Url return values are already defined, so while I could go back and add a slug to the MapRoute function and modify each ActionLink individually, I thought, surely there must be a better way.
I want to have the slugs automatically created for me so I don't have to go back and change all the routevalues everywhere I access a book or author. Every time a /Author/1
is referenced, I want it transformed into /Author/1/sir-arthur-conan-doyle
on the server. How can I accomplish that?