Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Chris King 6 posts 86 karma points
    Jul 27, 2022 @ 18:53
    Chris King

    Access Data from External Database

    Hello and thank you for looking. I am new to Umbraco and have really enjoyed it.

    Here is the scenario.

    I need to search for a case based on a name. From there a list of results will show. Clicking on a result will list the information for the case. All this info would come from the external Database.

    Any direction on how to achieve this is much appreciated.


  • Marc Goodson 1770 posts 11757 karma points MVP 7x c-trib
    Aug 14, 2022 @ 15:19
    Marc Goodson

    Hi Chris

    There are a couple of ways to achieve the kind of scenario you are talking about within Umbraco, and it will depend a little on the nuances of the case and the information to be displayed as what the best route it is for you to go.

    But I think one way might be to create a Cases DocumentType in Umbraco, with a Cases Template

    This would be the page you list your search results on.

    In Umbraco there is a technique called RouteHijacking that is based on a convention of a Custom MVC Controller matching the name of a DocumentType.


    So if you create a controller called CasesController that inherits from RenderController

    You will be able to create an Index action that intercepts all requests into the /cases Url, and from here you could read any search criteria from the querystring, take those criteria, query your database, find matching cases, and create a Custom ViewModel that inherits from Umbraco's default ContentModel, but with a new property 'CaseSearchResults' being an IEnumerable fo your matching database Case entities.

    Then your Umbraco Template/View can be updated to use your Custom ViewModel

    And you can use this to write out the list of Cases that match the search criteria...

    Now for your Search Form, you would need to handle it's 'post back' - and in Umbraco there is a special type of controller called a SurfaceController:

    That you hook up your form to post to. The surface controller then validates the form post, and if all looks good redirects the user to your /cases page with the specific querystring parameters to trigger the search.

    Finally, depending on how much data you have in your Case Study to display, you could create a new Document Type called CaseStudyInfo, and allow it to be created under your Cases page.

    Here you would create one page called DisplayCaseStudyInfo, and create another RenderMvcController CaseStudyInfoController (following the convention) and this could read the case study unique Id, and retrieve further information for the Case from the database, enrich another new custom ViewModel, that then gets sent to the template fo rthe CaseStudyInfo page to display the additional info...

    Now this would mean all your extra case information requests would have a similar Url eg /cases/displaycasestudyinfo?caseId=1234

    There is a further technique, to create a Virtual Controller

    That allows you to map a route to a virtual controller that could pull the case information from the database and present it 'as if it were' in Umbraco, so you could have URLs more like /cases/my-special-case

    if that were particularly important!

    Anyway hope that's all food for thought!



  • Chris King 6 posts 86 karma points
    Aug 24, 2022 @ 14:41
    Chris King

    Thank you Marc, I will give this a try! Chris

Please Sign in or register to post replies

Write your reply to: