0

I have an Episerver site with a JobDetailsPageController with a Index method that takes a jobId parameter and creates a view with some details about that job. The urls looks something like this: https://hostname/<root-depending-on-site-tree>/jobs/?jobid=44.

What I would like is having urls on the form .../jobs/manager-position-telco-44, essentiallly creating a slug of the job title and appending the id. I have done this in the past using standard ASP.NET MVC Attribute Routing on a non-Episerver site, but EpiServer has a routing of its own that I don't know too well and can't figure out.

Also, adding non-query strings after the slash consistently sends me (no surprise) to a 404 page, so I would need to somehow customise this behaviour. I need to use EpiServers standard routing to end up at the right "parent", but ignore the latter part (the pretty bit).

Is it possible to create such urls on a normal page in page tree in EpiServer? I do understand it is possible to create static routes, but this node can be moved around like any other page so I cannot avoid EpiServer.

oligofren
  • 20,744
  • 16
  • 93
  • 180

2 Answers2

3

Please see this blog post. What you're looking for is partial routing.

Johan Petersson
  • 972
  • 4
  • 13
  • I had already come across both of those, but when you are in a hurry massive amounts of tests in your googling quickly get overwhelming, so I really wasn't able to digest them quick enough to see that this was the right stuff. From a casual glance it seems to be able to do the trick nicely. I'll give you a upvote if it serves me right. Thanks! Just a tip when it comes to Stack Overflow etiquette and posting rules: answers that post to articles, rather than embed the content in the answer itself, are often frowned upon, as link rot makes these answers less valuable in time. FYI :) – oligofren Nov 03 '16 at 08:50
  • argh, auto-correct: "massive amounts of tests" = "massive amounts of text" – oligofren Nov 03 '16 at 09:40
  • Not sure if the API has changed, but you are referencing EPi9 documentation despite the fact that question is tagged with tag `episerver-7`. Correct link for EPi7 documentation is here: http://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/7/Routing/Partial-Routing/Partial-Routing/ – Kaspars Ozols Nov 03 '16 at 12:54
1

@johan is right, partial routing is one way of doing this. Just wanted to add other possible solutions that might or might not match your needs.

Import data as content

Instead of serving content dynamically, you could consider importing your job ads from whatever source you have directly in content tree as separate pages below particular root page. That would give you a lot benefits - pages would be cached, it would support multiple languages, editors would see content directly in EPiServer CMS, data could be adjusted manually, etc.

This would be a good solution if your data does not change often and you need to provide a way for editor to create a new job ad manually as well.

Implement you own content provider

Another way to serve your dynamic data to EPiServer is to write your own custom content provider. You can find documentation here: http://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/7/Content-Providers/Content-Providers/

This solution requires more coding and is more complex, but it has some benefits as well. If one wanted, it would be possible to not just serve content from external data source, but also update that data by changing values directly in EPiServer UI.

Kaspars Ozols
  • 6,967
  • 1
  • 20
  • 33