Copied to clipboard

Flag this post as spam?

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


  • Craig O'Mahony 364 posts 918 karma points
    Mar 31, 2015 @ 17:42
    Craig O'Mahony
    0

    Searching in Razor

    Hi all,

    I'm after some advice really....

    I have a page that displays a list of a folder of content and I've been asked to write a simple search that purely relates to the content that displayed on this page and I come from a usercontrol/webforms background. Using this approach I would have built a dataset of the content filtered it by what the user is posting in the search field and then returned these results back to the page but I'm trying to get away from the whole webforms area and into MVC/Razor. 

    Currently there isn't even a search field on the page as I'm unsure of how to even reference a field in Razor code. Could someone point me in the right direction please?

    This is how I'm currently rendering the content to the page....

    @{var node = Umbraco.TypedContent(1091);}
    @{
        foreach (var child in node.Children)
        {
            <h4><a href="@child.Url">@child.GetPropertyValue("courseTitle")</a></h4>
            <p>@child.GetPropertyValue("courseDescriptionSnippet")</p>
            if (@child.GetPropertyValue("courseImage") != "" && @child.GetPropertyValue("courseImage") != null)
            {
                var link = Umbraco.TypedMedia(@child.GetPropertyValue("courseImage"));
                <img src="/imagegen.ashx?width=150&[email protected]" />
            }
        }
    }

    Any help would be greatly appreciated

    Thanks, Craig

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 31, 2015 @ 17:50
    Dennis Aaen
    0

    Hi Craig,

    Perhaps you should take a look at the ezSearch package, it a seach functionally package for MVC sites, like the good old XSLTsearch with this package you can configure which fields, and document types that should be searchable.

    https://our.umbraco.org/projects/website-utilities/ezsearch

    Hope this can be a solution for you.

    /Dennis

  • Craig O'Mahony 364 posts 918 karma points
    Mar 31, 2015 @ 17:53
    Craig O'Mahony
    0

    Hi Dennis,

    Thanks for that but it looks like its not compatible with the version that I'm running 7.2.4 (probably should have put that in the original post!).

    Thanks,

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 31, 2015 @ 18:12
    Dennis Aaen
    0

    Hi Craig,

    I am currently working on a project where we are using ez Search for search functionality.

    The project is running Umbraco 7.2.1. So I think that you can use it for Umbraco 7.2.4 also. But if you decides to give the package a try. Then I would installed it on a test environment, and remember to take a backup before so you can make database rollback in the case something went wrong.

    /Dennis

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 31, 2015 @ 21:24
    Jan Skovgaard
    0

    Hi Craig

    There should be no issues using EZSearch on 7.2.4 - So you should be able to get it working. But as Dennis says make sure to keep a backup to be on the safe side. I think it should be enough to just backup files for this package though - Don't think it installs anything in the database.

    Let us know how things turn out.

    /Jan

  • Craig O'Mahony 364 posts 918 karma points
    Apr 01, 2015 @ 10:03
    Craig O'Mahony
    0

    Hi gents,

    Thanks for both your replies, the request has mutated into more of a custom search with filtering checkboxes etc.So I think that I'll have to write some sort of a custom control.....all I've got to work out is how to do it!

    Thanks

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 01, 2015 @ 10:21
    Jan Skovgaard
    0

    Hi Craig

    Ok...but perhaps you can base it upon EZsearch by just modifying the source to accomodate your needs? I suppose that the checkboxes represents some search keywords somehow?

    Anyway...start with figuring out the exact way it should work and then sketch it out and then you can see if EZSearch can be build upon - I think the source is public somewhere.

    Cheers, Jan

  • Craig O'Mahony 364 posts 918 karma points
    Apr 01, 2015 @ 17:31
    Craig O'Mahony
    0

    Thanks gents,

    I'm actually going around in circles on this!

    Rather than use the ezSearch plugin, I'd actually like to try and build something myself to try and learn the MVC way. So what I need to do is the following...

    1) Using the MVC 'framework' get a list of all child nodes under a certain node (which I've done in Razor) and display this complete list on a page by default.

    2) Somewhere on this page have a search textbox which when something is entered search through the child nodes and finds matches and then display this filtered list to the page 

    3) The page will also have a series of checkboxes that relate to specific properties in the child nodes that they may or may not contain. Again when selected filter the list again.

    Could someone give me a starting point please?

    Thanks,

    Craig

Please Sign in or register to post replies

Write your reply to:

Draft