locked
Blazor EditForm RRS feed

  • Question

  • User2041008840 posted

    Hello, 
    I am using Blazor. I wanat to insert the value into db. 

    <EditForm Model="@PurchaseItem" OnValidSubmit="@AddItem">
        <DataAnnotationsValidator></DataAnnotationsValidator>
    
        <div class="row mb-2">
    
            <div class="col-xl-4 col-lg-4 col-md-4 col-sm-12 col-xs-12">
                <div class="form-label-group">
                    <select id="txtStockID" @bind="@SelectedStockId" class="custom-select form-control-label">
                        @if (itemsLists == null || itemsLists.Length == 0)
                        {
                            <option value="@(0)">--select--</option>
                        }
                        else
                        {
                            <option value=@(0)>--select--</option>
                            @foreach (var item in itemsLists)
                            {
                                <option value="@item.ID">@item.Name</option>
                            }
                        }
                    </select>
                    <label for="txtStockID">Item</label>
                    <span class="text-danger"><ValidationMessage For="@(() => PurchaseItem.ItemsListID)" /></span>
    
    
    
                </div>
            </div>
            <div class="col-xl-2 col-lg-2 col-md-2 col-sm-12 col-xs-12">
                <div class="form-label-group">
                    <input id="txtQuantity" type="number" step="0.01" min="1" class="form-control form-control-label" @bind="@PurchaseItem.Quantity" placeholder="Quantity" />
                    <label for="txtQuantity">Quantity</label>
                    <span class="text-danger"><ValidationMessage For="@(()=> PurchaseItem.Quantity)" /></span>
                </div>
    
    
            </div>
            <div class="col-xl-1 col-lg-1 col-md-1 col-sm-12 col-xs-12">
                <div class="form-label-group">
                    <input id="txtRate" type="number" step="0.01" min="0" class="form-control form-control-label" @bind="@PurchaseItem.Rate" placeholder="Rate" />
                    <label for="txtRate">Rate</label>
                    <span class="text-danger"><ValidationMessage For="@(()=> PurchaseItem.Rate)" /></span>
                </div>
            </div>
    
            <div class="col-xl-1 col-lg-1 col-md-1 col-sm-12 col-xs-12">
                <div class="form-label-group">
                    <input id="txtDiscount" type="number" step="0.01" min="0" class="form-control form-control-label" @bind="@PurchaseItem.Discount" placeholder="Discount" />
                    <label for="txtDiscount">Discount</label>
                    <span class="text-danger"><ValidationMessage For="@(()=> PurchaseItem.Discount)" /></span>
                </div>
            </div>
    
            <div class="col-xl-2 col-lg-2 col-md-2 col-sm-12 col-xs-12">
    
                <div class="form-label-group">
                    <select id="txtTax" @bind="@SelectedTaxAmount" class="custom-select form-control-label">
                        @if (taxes == null || taxes.Length == 0)
                        {
                            <option value="@(0)">--select--</option>
                        }
                        else
                        {
                            <option value=@(0)>--select--</option>
                            @foreach (var item in taxes)
                            {
                                <option value="@item.Amount">@item.Amount</option>
                            }
                        }
                    </select>
                    <label for="txtTax">GST</label>
    
                </div>
    
            </div>
    
            <div class="col-xl-2 col-lg-2 col-md-2 col-sm-12 col-xs-12">
                <div class="form-label-group">
                    <input id="txtTotal" type="number" step="0.01" min="0" value="0" class="form-control form-control-label" placeholder="Total" readonly />
                    <label for="txtTotal">Total</label>
                </div>
    
                <div class="form-group text-right">
                    <button class="btn btn-primary" type="submit">Add</button>
                </div>
            </div>
        </div>
    </EditForm>

    but its showing me error in console 

    Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
    Unhandled exception rendering component: Microsoft.AspNetCore.Components.Forms.ValidationMessage`1[System.Single] requires a cascading parameter of type EditContext. For example, you can use Microsoft.AspNetCore.Components.Forms.ValidationMessage`1[System.Single] inside an EditForm.

    Whats the exact issue ? 

    Thursday, July 30, 2020 6:20 PM

All replies