Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

286
Vistas
Is it possible to create a Blazor component on button's onclick event

I am very new with Blazor. Hence all guidance and direction regarding my question is highly appreciated.

I am working on a Blazor page where I have implemented Blazorise open source library to implement <CardDeck>...</CardDeck> in a Page(eg. Parent.razor). Underneath that CardDeck I have implemented a Card inside razor component. And I am binding data objects retrieved from database.

Code for Parent.razor is like below.

    <CardDeck>
          <Button @onclick="SomeMethodToCreateComponent"
          @foreach(var item in List)
          {
             //implementing component page (eg. CardComponent.razor)
             <CardComponent>...</CardComponent>
          }
    </CardDeck>

    @Code{
        public void SomeMethodToCreateComponent()
        {
             //Code to create a component on button onclick
        }
    }

Code for component page (eg. Card.razor)


    <Card>
     <CardBody>
        <CardTitle Size="5">Card title 1</CardTitle>
        <CardText>
            Lorem ipsum
        </CardText>
        </CardBody>
    </Card>

Now there is an enhancement to this functionality. On parent razor page, I have a placed a button. On that button's @onclick event I need to generate a component with <Card>...</Card> hierarchy. Whenever the button in parent page is clicked, a card should be generated. Is it possible?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It is much simpler than you think.

public void SomeMethodToCreateComponent()
{
     //Code to create a component on button onclick
     var newItem = ...
     List.Add(newItem);
} // auto re-render here and the @foreach will render the new item
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda