Hi all,
I am working on a .net core project in with blazor.
I am facing a issue in loading TelerikListView. When datasource is null, TelerikListView not displaying. There are so many controls like dropdown, textbox, radio buttion are there inside this. I have assigned a IEnumerable class to this Listview. When it has data, the Listview is displaying thus all controls also.
The inside controls value are binding from another datasource. Pls help me to solve this issue Know the answer? Post it — somebody with the same question will find it here. Sign in to answer this question It is the same account you read, post and publish with — and you will come straight back to this page.
3 Replies
Brahma Prakash ShuklaPosted Jul 19, 2023, 5:40 AM
Based on your updated explanation, it appears that the issue lies in the way you are handling the
modelandchangemodelobjects. Since the ListView is not displaying when themodelis null, we need to ensure that the data source for the ListView is correctly populated in both cases: when themodelhas data (during update) and when it's null (during insert).To achieve this, you can follow these steps:
IEnumerablefor ListView: Instead of using the sameIEnumerablefor both the ListView and thechangemodelvariable, create a separate variable specifically for the ListView's data source. This will prevent any conflicts during the insert process.Fetch Data for ListView: When loading the ListView, populate the
ListViewDatawith the data you want to display in the ListView. You can either use theChangemodeldirectly or apply any filtering or transformation you need for displaying the data in the ListView.Bind ListView Data: In the Razor markup, bind the
ListViewDatato theDataparameter of the TelerikListView.Handle Null Model during Insert: In the insert process, when the
modelis null, make sure to create a new instance ofChangeModeland add it to theChangemodelcollection. This way, you have an item to display in the ListView.By following these steps, you should be able to display the ListView with the newly added item during the insert process when the
modelis null. Additionally, you can handle updates normally, as you are doing withmodel = await Planning.GetFormAsync(51);.Bineesh ViswanathPosted Jul 17, 2023, 1:39 PM
Brahma Prakash Shukla,
Thank you for valuable suggestions
I found most of the cause for the issue. I am using same class object for both insert and update process.
above is the object i am passing to data parameter of listview. during update process, all going normally since the object has data
above one i passing to the ref parameter of blazor page.
below is the code using for insert purpose
first, I calling one method i using for update process to get id based data.
1) model = await Planning.GetFormAsync(51);// if i pass id data fetched to model object and form showing
2) changemodel = Changemodel.FirstOrDefault();
point 1 and 2 working fine. below is the code i want to make it work. since the model is null, listview not displaying
model = await PlanningService.GetFormAsync(0);// in case id is zero, getting null model
changemodel = Changemodel.FirstOrDefault();
Brahma Prakash ShuklaPosted Jul 14, 2023, 11:47 AM
In your Blazor project, if the Telerik ListView component is not displaying when the data source is null, you can try the following approach to handle this issue.
First, ensure that you have the necessary Telerik UI for Blazor dependencies installed in your project. You can use the Telerik NuGet packages and include the required CSS and JS files.
To handle the scenario where the data source is null and the Telerik ListView is not displaying, you can use conditional rendering in your Blazor component. Here's an example:
In this example, the
@ifdirective checks if theContractorsdata source is null. If it's not null, the Telerik ListView component with its associated controls and bindings will be rendered. Otherwise, a simple message or placeholder can be displayed to indicate that there is no data available.Make sure to adjust the code based on your specific implementation, including the property names, data sources, and control bindings.
By using conditional rendering, you can control when the Telerik ListView component should be displayed based on the availability of data in the data source.