views:

21

answers:

2

Hello!

I am having trouble to what i should name this in the title field...

Question is. I want to select a blogpost by entering its title, like this: http://localhost:3254/blog/2010/10/net-programming

The title of the blogpost should be ".net programming". So i have setup a route to look for a year a month and finally a string. But how should i save this in the database to be able to search for it? Should i add a field, like id, that contains asp-programming? or should i parse the title for every search? or should i convert the title and then convert it back before displaying it to the user?

A: 

There are two possible solutions I can think of

  • Create your own Route handler and within its code, search for the actual record in the database
  • Create an action method in a Controller that accepts a string parameter and call that parameter id (or whatever the default is in your MapRoutes method).
Venemo
+2  A: 

The standard method is to create a separate column in the database (usually called 'slug' or permalink) that stores the html-friendly name that may be used by Urls. Then, if the title of the post changes you would normally keep the slug the same so that anyone who has bookmarked the link can still find the post. The value us usually defaulted from the blog title, replacing spaces with - and removing any non url friendly characters.

http://en.wikipedia.org/wiki/Slug_%28web_publishing%29

Clicktricity