0

hello I try to build a small cms. I have manage to store all my content to my database and now I want to call it through a menu from my _layoutpage. (I have built my details page) How can I pass the id for every article in an action link and then at the url to display the alias?

I have used the following code

<li>@Html.ActionLink("History", null, "SiteContents",new { id ="ArticleDetails/1" }, null)</li>

EDIT I correct my code to

<li>@Html.ActionLink("History", "ArticleDetails", "SiteContents",new { id ="1" }, null)</li>

and it works.

Does anyone know how can I bring an alias (I have stored it as a field in my database) to the url so not the id to be appear. thank you.

touinta
  • 971
  • 3
  • 10
  • 26
  • Do you mean you want a 'slug' (i.e like the url in address bar you looking at now)? –  Feb 23 '16 at 08:54
  • Yes that is what I mean. thank you. how can I call it from my db? – touinta Feb 23 '16 at 09:01
  • Not clear exactly what you want, but have a look at [this answer](http://stackoverflow.com/questions/30349412/how-to-implement-url-rewriting-similar-to-so/30363600#30363600) –  Feb 23 '16 at 09:09
  • I mean that I have store a slug for every article in my database. How can I call it at the url? – touinta Feb 23 '16 at 09:42
  • Sorry I don't understand your comment - did you try the code I linked to? –  Feb 23 '16 at 09:44
  • Yes I tried it it gives me http://localhost:xxxx/SiteContents/ArticleDetails/1?slug=slug – touinta Feb 23 '16 at 10:19
  • Then you have not implemented it correctly :) –  Feb 23 '16 at 10:22
  • I am still trying :) What I need to put as a parameter at my action link? thank you... – touinta Feb 23 '16 at 11:31
  • hey I manage to bring SiteContents/ArticleDetails/1?slug=this-is-a-slug , but why it brings "slug=" and not just the "this-is-a-slug" – touinta Feb 23 '16 at 12:26
  • It doesn't. You obviously have made a mistake somewhere. If you use the exact code in the linked answer, then `Question/1` will result in the url being `Question/1/this-is-a-slug` and `Question/1/this-is-a-slug` will result in `Question/1/this-is-a-slug` and `Question/1?slug=this-is-a-slug` will result in `Question/1?slug=this-is-a-slug` In the case of the first one, the code in the `if` block will be executed, and or the other 2 it wont. –  Feb 24 '16 at 02:26

0 Answers0