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 87 karma points
    Jul 27, 2022 @ 18:53
    Chris King
    0

    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.

    Chris

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Aug 14, 2022 @ 15:19
    Marc Goodson
    0

    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.

    (https://our.umbraco.com/documentation/reference/routing/custom-controllers/)

    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:

    https://our.umbraco.com/Documentation/Reference/Routing/Surface-Controllers/

    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

    https://our.umbraco.com/documentation/Reference/Routing/Custom-Routes/#custom-route-with-ivirtualpagecontroller

    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!

    regards

    Marc

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

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

Please Sign in or register to post replies

Write your reply to:

Draft