Using Listview without Ajax Datasource binding

1 Answer 53 Views
ListView
Charlston
Top achievements
Rank 1
Charlston asked on 28 Sep 2023, 03:06 PM

I am trying to find a way to populate a Listview without the need to create a Read action. currently, in my Controller class, I have an action method that gets called with a query string. 

Controller.cs

public IActionResult Report(string blocknumber)
     {
         var model = new List<Report>();
         model = _maExtensionService.GetReport(blocknumber).Result.ToList();
         ViewBag.BlockList = model;
         return View();
     }

 

My cshtml

Report.cshtml

 

@(Html.Kendo().ListView<Report>(ViewBag.BlockList as IEnumerable<Report>)
    .Name("Reportgrid")
    .TagName("div")
    .Pageable())

 

I have tried to use ViewBag in different ways and also Viewdata to bind and or hold data to be used on the page. When the page loads I am not seeing data populate the Listview. Is there another way I should be doing this? Thank you for your time

1 Answer, 1 is accepted

Sort by
0
Anton Mironov
Telerik team
answered on 03 Oct 2023, 11:09 AM

Hi Charlston,

Thank you for the code snippets and the details provided.

In order to achieve the desired behavior, I would recommend using the approach from the following demo:

The code for the implementation can be found in the "View Source" tab in the demo above. The "GetProducts" Method of the "IndexController" is populating the ViewModel. This ViewModel is than used in order to populate the ListView.

Give a try to the approach from the demo and let me know if further assistance or information is needed.

Kind Regards,
Anton Mironov
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.

Charlston
Top achievements
Rank 1
commented on 03 Oct 2023, 01:27 PM

I have tried whats in the demo. The view is still empty below is my updated code from my cshtml page 

@model List<Report>

<script type="text/x-kendo-tmpl" id="template">
    <div class="reportList">
        <span>
            #:FirstName#
        </span>
    </div>

</script>@(Html.Kendo().ListView<Report>(Model)
    .Name("fdxBlockReportgrid")
    .TagName("div")
    .ClientTemplateId("template")
    .Pageable()
    .DataSource(d => d  
        .Ajax()
        .ServerOperation(false)
        .PageSize(50))
    
        
    ) 

 

Report.cs

private string? _memberFullName;
        public string FirstName { get; set; } = string.Empty;
        public string LastName { get; set; } = string.Empty;
        public string? Mi { get; set; } = string.Empty;


        public string Seniority { get; set; }
        public string MemberClass { get; set; }


        public string MemberName
        {
            get
            {
                string middleInitial = ((Mi != null) && (Mi.Trim().Length > 0)) ? " " + Mi.Trim() + "." : "";
                string fullName = "";
                if ((FirstName != null) && (LastName != null))
                {
                    fullName = LastName.Trim() + ", " + FirstName.Trim() + middleInitial;
                }
                return _memberFullName ?? fullName;
            }
            set
            {
                _memberFullName = MemberName;
            }
        }
Anton Mironov
Telerik team
commented on 03 Oct 2023, 01:34 PM

Hi Charlston,

Thank you for the additional details provided.

Could you please double-check the Developer Tools Console of the browser for any JavaScript errors?

Furthermore, it would be perfect if you could provide a runnable sample where the issue is represented(remove the bin, obj, and packages folders and send the sample back to me in this thread). Once I have the runnable sample will try my best to achieve the desired result.

Looking forward to hearing back from you.


Best Regards,
Anton Mironov

Charlston
Top achievements
Rank 1
commented on 03 Oct 2023, 02:16 PM

The error message is saying Kendo is undefine 

my viewimport.cshtml :

@using Report.Web
@using Report.Web.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

@addTagHelper *, Kendo.Mvc
@using Kendo.Mvc.UI
@using Extension.Models.DomainEnity
@using Report.Web.Controllers
@using Kendo.Mvc.Extensions
Charlston
Top achievements
Rank 1
commented on 03 Oct 2023, 02:30 PM

I understand why I'm getting undefine. It is because I didnt add the link and script ref to kendo in the Layout.cshtml.
Anton Mironov
Telerik team
commented on 06 Oct 2023, 09:03 AM

Hi Charlston,

I am glad to hear that the issue is now rsolved.

If further assistance or information is needed, do not hesitate to contact me and the team.

Best Regards,
Anton Mironov

Tags
ListView
Asked by
Charlston
Top achievements
Rank 1
Answers by
Anton Mironov
Telerik team
Share this question
or