Skip to content

Possible bug with for loop #15618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
stsrki opened this issue Sep 14, 2018 · 2 comments
Closed

Possible bug with for loop #15618

stsrki opened this issue Sep 14, 2018 · 2 comments
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@stsrki
Copy link
Contributor

stsrki commented Sep 14, 2018

I have a SimplePagination component with just the basics:

<Pagination>
    @for ( int i = 0; i <= ( TotalItems / PageSize ); ++i )
    {
        <PaginationItem>@i.ToString()</PaginationItem>
    }
</Pagination>
@functions{
    [Parameter] int TotalItems { get; set; }

    [Parameter] int PageSize { get; set; } = 10;
}

Use case:

<SimplePagination TotalItems="5" />
<SimplePagination TotalItems="15" />
<SimplePagination TotalItems="45" />

When rendered I get this:
image

But if I store the page number inside of temp var I get the expected result:

<Pagination>
    @for ( int i = 0; i <= ( TotalItems / PageSize ); ++i )
    {
        var pageNum = i.ToString();
        <PaginationItem>@pageNum</PaginationItem>
    }
</Pagination>
@functions{
    [Parameter] int TotalItems { get; set; }

    [Parameter] int PageSize { get; set; } = 10;
}

image

I guess that ChildContent inside of my PaginationItem will only get the reference to the ToString() function instead of it's return value.

Is this expected behavior ?

@campersau
Copy link
Contributor

@SteveSandersonMS
Copy link
Member

Thanks for answering, @campersau!

@mkArtakMSFT mkArtakMSFT transferred this issue from dotnet/blazor Oct 27, 2019
@mkArtakMSFT mkArtakMSFT added area-blazor Includes: Blazor, Razor Components and removed area-blazor Includes: Blazor, Razor Components labels Oct 27, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

4 participants