asked    Lydia     2018-10-12       asp.net-mvc       17 view        1 Answer

[SOLVED] How to get specific fields to be shown in the search results?

I'm using ezSearch package installed into Umbraco 7.6. What I am trying to do is to get specific fields to be always shown in the search result under the pageName that has the word that the user is looking for,

So for example I have two properties in the homepage (heading1 and homeText)

And the code for (search results) in the macro as following:

@helper RenderContentResult(SearchViewModel model, IPublishedContent result)
{
    <div class="ezsearch-result">
        <h2><a href="">@result.Name</a>XX</h2>

        @foreach (var field in model.PreviewFields.Where(field => result.HasValue(field)))
        {
            <p>@Highlight(Truncate(Umbraco.StripHtml(result.GetPropertyValue(field).ToString()), model.PreviewLength), model.SearchTerms)</p>

            break;
        }
    </div>
}

Thank you!

  1 Answer  

        answered    Frederic     2018-10-12      

Since result is an IPublishedContent you can access whatever property you want, e.g.

result.GetPropertyValue<string>("homeText")

or

@(result.GetPropertyValue<string>("homeText"))

anywhere in RenderContentResult depending on the needed Razor syntax





Your Answer





 2018-10-12         Vivien

What port does Courier for Umbraco use?

I have had a few problems setting up Courier for umbraco (v7).After a bit of trial an error I have discovered the destination server has all its ports blocked other than 80.Does anyone know what port I need to open up to get it to work? I'm pretty sure Courier just runs over port 80, as it's all web based. [XXX]
 umbraco                     1 answers                     97 view
 2018-10-12         Joan

How to check which html tag is the title field using in umbraco

Is there a way to check on backend which tag user is using for title field on any content page. e.g. h1 or h2 in Umbraco Umbraco doesn't have a specific template that is used for all sites built using Umbraco. As such, its difficult to answer your question directly. Here are some ways you could find out:In your browser, right-click and either "View Source" or "Inspect Element" and find the title that you are looking to get more information for. If you add something unique (a * or some character) that may help you to find it. The text of the title should have the h1 o...
 jquery                     1 answers                     98 view
 2018-10-12         Philip

How to load Razor partial view in jQuery without using MVC?

I am working on a Umbraco 7 project started without MVC implemented. I try to implement a loading without page refresh. I am stuck now because I need some Razor code to get Umbraco information but I need jQuery to refresh without page refresh.Here my code:$(function () { $.ajaxSetup({ cache: false }); $('#filterButton').click(function(){ $('#content').html(@Html.Partial("~/Views/Partials/Preferences.cshtml")); }) });I tried with .load()with .html using @Html.Action,@Html.Partial etc, but nothing ...
 c#                     2 answers                     99 view