Skip to content

Instantly share code, notes, and snippets.

@fluxdigital
Created September 16, 2022 00:00
Show Gist options
  • Save fluxdigital/16ef860e45f9cfc3d05ab7a8e3ce74e7 to your computer and use it in GitHub Desktop.
Save fluxdigital/16ef860e45f9cfc3d05ab7a8e3ce74e7 to your computer and use it in GitHub Desktop.
BlogPostSearchResults.cshtml
@using Glass.Mapper.Sc.Web.Mvc
@using FluxDigital.Feature.Search.Models
@using PagedList.Mvc
@using Sitecore.Configuration
@model BlogPostSearchResultsModel
<div class="wrapper">
<form class="search" action="" method="GET">
<div class="search-box">
<input type="search" name="SearchTerm" placeholder="Enter Search Text" title="Search term" value="@Model.SearchTerm">
<button type="submit" title="search" class="button">Search</button>
<br />
</div>
</form>
@if (string.IsNullOrEmpty(Model.SearchTerm))
{
<div>Please enter a search term.</div>
}
else
{
<h2>Search Results</h2>
<section id="searchresults">
<ul class="searchresults-items">
@if (Model.SearchResults != null && Model.SearchResults.Count > 0)
{
foreach (BlogPostSearchResult searchResult in Model.SearchResults.ToList())
{
<li>
<a href="@searchResult.ItemUrl">
@Html.Raw(HttpUtility.HtmlDecode(searchResult.Title))
</a>
<p>
@Html.Raw(HttpUtility.HtmlDecode(searchResult.Description))
</p>
</li>
}
}
else
{
<div>No Results Found</div>
}
</ul>
<!--pagination-->
<div class="pagination m-pad-sides mobile-hidden tablet-hidden">
@if (Model.SearchResults != null)
{
@Html.PagedListPager(Model.SearchResults, page => string.Format("?page={0}&searchterm={1}", page, Model.SearchTerm), new PagedListRenderOptions { LinkToFirstPageFormat = "<< First", LinkToPreviousPageFormat = "< Prev", LinkToNextPageFormat = "Next >", LinkToLastPageFormat = "Last >>", MaximumPageNumbersToDisplay = 5 })
}
</div>
</section>
}
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment