This is a migrated thread and some comments may be shown as answers.

Blazor for Beginners code error in OnSelected

2 Answers 97 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kenneth
Top achievements
Rank 1
Kenneth asked on 26 Mar 2020, 01:27 PM

Is anyone using the code from the free book and getting it to build/run?

I can't get past the event call back code on pages 46-47. I find the code references OnSelected="HandleItemSelected" delegate when no procedure/var exists with that name. I think I need to add a delegate to WeatherDay component.

Book:

<WeatherDay TemperatureC="forecast.TemperatureC"
Summary="@forecast.Summary"
DayOfWeek="forecast.Date.DayOfWeek"
OnSelected="HandleItemSelected"
Selected="forecast.Selected">

I tried:

<WeatherDay TemperatureC="forecast.TemperatureC"
Summary="@forecast.Summary"
DayOfWeek="forecast.Date.DayOfWeek"
OnSelected="HandleOnSelected"
Selected="forecast.Selected">

2 Answers, 1 is accepted

Sort by
0
Accepted
Marin Bratanov
Telerik team
answered on 27 Mar 2020, 10:19 AM

Hi Kenneth,

Thank you for reaching out. Indeed, it seems that a sample handler is missing from the book, and I will forward this issue to the people working on it.

Here's a sample handler that you can try in the WeeklyForecast.razor file (I am also attaching a runnable project that demonstrates it):

    async Task HandleItemSelected(DayOfWeek day)
    {
        WeatherForecast selectedForecast = forecasts.Where(f => f.Date.DayOfWeek == day).First();
        if(selectedForecast != null)
        {
            selectedForecast.Selected = !selectedForecast.Selected;
        }
    }

 

Regards,
Marin Bratanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
DR
Top achievements
Rank 1
commented on 21 Jan 2022, 03:12 PM

Almost 2 years later, and the book has not yet been corrected?

Also other 'typos' like

above  Summary="@forecast.Summary" where the leading @ is not needed

page 25 "API endpionts for data"  (endpoints spelled wrong)

page 33 "where it should to be placed"

page 66 "diffing algorithm to to ensure"

Hristian Stefanov
Telerik team
commented on 26 Jan 2022, 08:34 AM

Hi Dennis,

I've reached out to the author of the book. We are now waiting for a response. I will keep you updated.

Thank you for your patience while we investigate the matter here.

Ed
Top achievements
Rank 1
Iron
commented on 02 Feb 2022, 09:46 PM

above  Summary="@forecast.Summary" where the leading @ is not needed

Addressing the typos, however the statement above is correct.

Because the parameter Summary is a String, if the `@` is omitted then the value becomes the string literal "forecast.Summary" and not the value of the property `forecast.Summary`.

0
Ed
Top achievements
Rank 1
Iron
answered on 26 Jan 2022, 05:18 PM

Thanks for making me aware of these issues. There are currently plans to replace the ebook with a much larger and complete ebook from O'Riley for free to our customers and community 🥳

In the mean time Ill see if theres a way to quicky address the typos described here.

Best regards,

Ed Charbeneau

DR
Top achievements
Rank 1
commented on 27 Jan 2022, 03:57 PM

Thanks Ed.  Hopefully you will use Visual Studio 2022 / .NET 6, and address the warnings, etc. ;)

(Also, for Theme Chooser demo, it's not clear about where light.css and dark.css come from and where to reference them.)

 

 

 

Ed
Top achievements
Rank 1
Iron
commented on 02 Feb 2022, 08:55 PM

It was implied that there was a theoretical app with light and dark themes, no code for those .css files is shown in the e-book. However, you can easily create them using a tool like themebuilder.telerik.com or visit https://bootswatch.com/ (see Darkly & Flatly).
Ed
Top achievements
Rank 1
Iron
commented on 02 Feb 2022, 09:04 PM

There's also a GitHub repo. I'm updating it for .NET 6 per your request. https://github.com/EdCharbeneau/BlazorBookExamples
Ed
Top achievements
Rank 1
Iron
commented on 02 Feb 2022, 09:41 PM

The GitHub project is updated to .NET 6. I think the warnings you refer to are due to the new `Nullable` feature in C# 9? These warnings can get quite bothersome in Razor. I addressed them in the repo, but it will take time to get the edits into the book.
Tags
General Discussions
Asked by
Kenneth
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Ed
Top achievements
Rank 1
Iron
Share this question
or