Binding Search Results

3 posts, 0 answers
  1. Sherman
    Sherman avatar
    21 posts
    Member since:
    Apr 2014

    Posted 05 Dec 2014 Link to this post

    Hi there, it's my first time trying to do a search result binding using ASP.NET MVC + ListView. I have included the source codes below. Please let me know if there is anything I should modify, and what I need to do to get it to work.

    1. Search Form
    01.<div class="content-wrapper">
    02.    <div class="search-wrapper">
    03.        @using (Html.BeginForm("Search", "Home", FormMethod.Post, new { id="search-form" }))
    04.        {
    05.            <div class="search-top-panel">
    06.                <input id="tbKeywords" name="tbKeywords" type="text"
    07.                       class="k-textbox" style="width: 600px; font-size: 24px;"
    08.                       required validationmessage="Enter a keyword"
    09.                       placeholder="Enter a Keyword" />
    10.            </div>
    11.            <div class="search-bottom-panel">
    12.                <div class="search-bottom-left-panel">
    13.                    @Html.ActionLink("Advance Search Options", "Index", "Home", new { search="adv" }, new { @class="standard-link" } )
    14.                </div>
    15.                <div class="search-bottom-right-panel">
    16.                    @(Html.Kendo().Button().Name("btnSearch").Content("Hit It!").HtmlAttributes(new { type = "submit", @class = "k-primary" }))
    17.                </div>
    18.            </div>
    19.        }
    20.    </div>
    21.</div>

    2. Backend Code
    01.[HttpPost]
    02.public ActionResult Search()
    03.{
    04.    ViewBag.Keywords = Request.Form [ "tbKeywords" ];
    05. 
    06.    VideoRepository videoRepository = new VideoRepository ( );
    07. 
    08.    List<string> keywords = new List<string> ( );
    09. 
    10.    keywords = Request.Form [ "tbKeywords" ].Split ( new char [ ] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries ).ToList ( );
    11. 
    12.    IList<Video> lstResults = new List<Video>();
    13. 
    14.    IList<Video> videos;
    15.     
    16.    foreach(string keyword in keywords)
    17.    {
    18.        videos = videoRepository.GetAll ( ).Where ( v => v.VIDEO_TITLE.Contains ( keyword ) || v.VIDEO_DESC.Contains ( keyword ) ).ToList ( );
    19. 
    20.        foreach(Video v in videos)
    21.        {
    22.            if ( !lstResults.Contains ( v ) )
    23.                lstResults.Add ( v );
    24.        }
    25.    }
    26. 
    27.    ViewBag.Results = lstResults;
    28. 
    29.    return RedirectToAction ( "Index", new { view = "results" } );
    30.}

    3. ListView
    01.@if (Request.QueryString["view"] == "results")
    02.{
    03.    <div class="ui-memberVideolist" style="width: 100%;">
    04.        @(Html.Kendo().ListView<TheWebDevChannel.Models.VideoManagement.Video>(ViewBag.Results)
    05.            .Name("lvMemberVideoList")
    06.            .TagName("div")
    07.            .ClientTemplateId("template")
    08.            .Pageable()
    09.        )
    10.    </div>
    11.}

    I do recognize that my list view is incomplete code, because I am not exactly sure what else is required.
  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 10 Dec 2014 Link to this post

    Hello Sherman,

    The ListView setup seems correct. Providing data in the ListView constructor `ListView<TheWebDevChannel.Models.VideoManagement.Video>(ViewBag.Results)` should be working correct. 

    This approach is demonstrated here: ListView Basic Usage.

    Can you provide more details like:
     - What's the result when all this executes?
     - Are there JavaScript errors?
     - Are there any server errors?
     - Does the widget render empty?
     - Can you access the ListView client object

    You can also check whether all scripts are registered in right order, i.e kendo.all.min.js followed by kendo.aspnetmvc.min.js.

    Regards,
    Nikolay Rusev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Sherman
    Sherman avatar
    21 posts
    Member since:
    Apr 2014

    Posted 13 Dec 2014 in reply to Nikolay Rusev Link to this post

    Hi there! Thanks for letting me know. All the files are in place. Anyway, I didn't have a chance to replicate the issue, cause I managed to solve it already. Haha!

    I just realized that I could do it in 2 ways:

    1. ((IEnumerable<TheWebDevChannel.Models.VideoManagement.Video>) ViewBag.Results)

    and the other way was much simpler, I just post the results to a new view for the search results (provided my screenshot). Hope this helps others as well.
Back to Top