Blazor "@for(int ix=0; ix < listOfElements.Count(); ix++;)" does not work in razor pages

Anders Jansson 21 Reputation points
2023-12-14T14:47:42.7833333+00:00

bild

This construct does not work, without the last ";" in the increment of ix, whole page get erroneous!
Red swirls everywhere
bild

In the first case, the error says:

bild

which is wrong! Seems something really fishy here, looks like a bug!

This is in the Index page, for a Blazor component called Project and the the definition of projectList is:

@page "/projects"
@inject Obfuscation.Data.ProjectDbContext DB
.....
@code {
    IQueryable<Project>? projectList;
    protected override async Task OnInitializedAsync()
    {
        projectList = DB.Projects.AsQueryable();
    }
}

The definition of ProjectsDbContext is:


    public class ProjectDbContext : DbContext
    {
        public ProjectDbContext(DbContextOptions<ProjectDbContext> options) : base(options)
        {
        }
        protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
        {
            base.ConfigureConventions(configurationBuilder);
            configurationBuilder.Conventions.Remove(typeof(ForeignKeyIndexConvention));
        }
        public DbSet<Project> Projects { get; set;}
        public DbSet<File> Files { get; set;}
        public DbSet<Field> Fields { get; set;}
    }
    public class Project
    {
        [Key]
        [Required]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        [Required]
        [MaxLength(60)]
        [Display(Name = "Project Owner Id")]
        public string OwnerId { get; set; } = string.Empty;     // UserId from AspNetUsers

        [Required]
        [MaxLength(60)]
        [Display(Name = "Project Owner Name")]
        public string OwnerName { get; set; } = string.Empty;   // Name as registered.

        [Required]
        [MaxLength(150)]
        [Display(Name = "Project Name")]
        public string Name { get; set; } = string.Empty;

        public List<File> Files { get; set; } = new List<File>();
    }
    public class File
    {
        [Key]
        [Required]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }
        [Required]
        public int ProjectId { get; set; }
        [Required]
        [MaxLength(200)]
        public string Name { get; set; } = string.Empty;

        public List<Field> Fields { get; set; } = new List<Field>();
    }
    public class Field
    {
        [Required]
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        [Required]
        public int FileId { get; set; }

        [Required]
        public string Algorithm { get; set; } = string.Empty;

        [MaxLength(500)]
        public string? Description { get; set; }
    }
}

Version of Visual Studio My versions of everything:

Microsoft Visual Studio Community 2022
Version 17.9.0 Preview 2.0
VisualStudio.17.Preview/17.9.0-pre.2.0+34407.89

Microsoft .NET Framework Version 4.8.09037
Installed Version: Community
Visual C++ 2022 00482-90000-00000-AA408
Microsoft Visual C++ 2022
ASP.NET and Web Tools 17.9.153.1332

ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.9.153.1332 Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools 17.9.153.1332 Azure Functions and Web Jobs Tools

C# Tools 4.9.0-2.23578.7+984df16640ed69599894e05b974b2e741423a623 C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter 17.0.23314.1 Provides tools for finding, instantiating and customizing templates in cookiecutter format.

Extensibility Message Bus 1.4.39 (main@e8108eb) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio 17.9.0 (b3bca6f) Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 6.9.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Python - Profiling support 17.0.23314.1 Profiling support for Python projects.

Python with Pylance 17.0.23314.1 Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Razor (ASP.NET Core) 17.9.2.2357901+dfac5e3cec112dd38af95d899f85347f2e64411a Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.9.39.0 Microsoft SQL Server Data Tools

Test Adapter for Boost.Test 1.0 Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test 1.0 Enables Visual Studio's testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory.

TypeScript Tools 17.0.21025.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.9.0-2.23578.7+984df16640ed69599894e05b974b2e741423a623 Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.8.0-beta.23570.1+e9491ad27f8c9399cdd68e2308e906851a6db84f Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio.

VisualStudio.DeviceLog 1.0 Information about my package

VisualStudio.Mac 1.0 Mac Extension for Visual Studio

VSPackage Extension 1.0 VSPackage Visual Studio Extension Detailed Info

Xamarin 17.9.0.62 (main@1a123c3) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 17.9.2.9 (remotes/origin/d17-9@dba677e96e) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android SDK 13.2.2.0 (d17-5/45b0e14) Xamarin.Android Reference Assemblies and MSBuild support.

Mono: d9a6e87
Java.Interop: xamarin/java.interop/d17-5@149d70fe
SQLite: xamarin/sqlite/3.40.1@68c69d8
Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,672 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,546 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.