I am building my first .NET MVC web application and loving the simplicity and flexibility. I have however come to my first stumbling block.
I have a list of items and if you are not logged in you will see a preview link I would like the link to direct to something like below:
/preview/unique-slug
The view should then allow me to display the contents from the database (essentially a details page)
I am not sure how to approach this nor what I should be Google’ing as the results I got were poor.
Any pointers please?
This is the way I’ve done this in the past:
You need to store in the database a column with the slug that each item is referred to by. Then, create a route like the following:
So this will call the
Detailsmethod on thePreviewControllerlike so:Basically, you’ll get the slug as a string in your action method, query the database for the item with the corresponding slug, and display it. Essentially, we just replace an integer
idwith a stringslug.Hopefully that clears things up for you!