No tienes acceso a esta clase

¬°Contin√ļa aprendiendo! √önete y comienza a potenciar tu carrera

Creando formulario para agregar registros

15/19
Recursos

Aportes 4

Preguntas 1

Ordenar por:

¬ŅQuieres ver m√°s aportes, preguntas y respuestas de la comunidad?

AddProduct.razor


@page "/addproduct"

@inject  IProductService productService;
@inject  ICategoryService categoryService;
@inject  NavigationManager NavigationManager;

<PageTitle>Add - Product</PageTitle>

<ModuleTitle Title="Add product"/>

<button class="btn btn-dark" @onclick="@(()=> NavigationManager.NavigateTo("/product"))"></button>
<EditForm Model="@product">
    <div class="row">
            <div class="col-8 form-group">
                <label for="title" class="col-form-label"> Title</label>

                <InputText id="title" @bind-Value="product.Title" required class="form-control"/> 
           </div>
    </div>
</EditForm>


@code{
    private Product product=new();


 }

Products.razor


@page "/product"

@inject ILogger<Products> logger;
@inject  IProductService productService;
@inject  NavigationManager NavigationManager;

<PageTitle>Products</PageTitle>

<ModuleTitle Title="Products"/>
<button class="btn btn-dark" @onclick="@(()=> NavigationManager.NavigateTo("/addproduct"))"></button>
@if (products?.Count > 0){
    <div class= "products-container">
            @foreach (var product in products)
            {
                <div class="card">
                    <img class="card-img-top" src="@product.Images[0]" alt="Product" loading="lazy" width ="270" height="210">
                    <div class="card-body">
                        <h4><b>@product.Title</b></h4>
                        <p>@product.Price?.ToString("C")</p>

                    </div>
                </div>
            }
    </div>

 
 }
else{
 <p>
    No hay productos para mostrar.
 </p> 
 
 }

@code{
    private List<Product>? products;

protected override async Task OnInitializedAsync()
{
    products=await GetProducts();
}
    private async Task<List<Product>> GetProducts(){
          return await productService.Get();
    }

 }
En mi encontré esta forma de crear la navegación para la pagina de creación de producto. `<button class="btn btn-dark" @onclick="GoToNewProductPage"> </button>` `@code ` `{` ` private string urlNewProduct = "/product"; ` ` private Product product = new();` ` private void GoToNewProductPage() {` ` NavigationManager.NavigateTo("/product");` ` }` `}` Espero les resulte util para asi evitar el problema de las comillas

Código de la clase:

@page "/addproduct"
@inject ILogger<Counter> logger;
@inject IProductService productService;
@inject ICategoryService categoryService;
@inject NavigationManager navigationManager


<PageTitle>Add - Product</PageTitle>

<ModuleTitle Title="Add product"/>

<button class="btn btn-dark" @onclick="@(()=>navigationManager.NavigateTo("/product"))">Go back Products</button>
<EditForm Model="@product">
    <div class="row">
        <div class="col-8 form-group">
            <label for="title" class="col-form-label">Title</label>
            <InputText id="title" @bind-Value="product.Title" required  class="form-control"/>
        </div>
    </div>

</EditForm>

@code
{
 
 private Product product = new ();

}