This editform allows the user to edit a product from my products table. The data will then be updated to the database. This worked fine. Then I added my final 'comment' box. See I have an audit table which will record when any edits are made to the products. The audit record contains: an ID, the ID of the product being changed, the ID of the user making the change, the audit date and a comment. The validation of the other fields e.g. product.productname works but now I have a comment box where the validation is not being checked and is causing an error. I think it has to do with the fact that a Model is passed so that the models validation can be checked but when I tried to add a second model for the audit everything went red.
<EditForm Model=@selectedProduct OnValidSubmit="HandleSubmit">
<DataAnnotationsValidator />
<div class="form-group">
<label for="productName">Name:</label>
<InputText name="productName" @bind-Value="selectedProduct .ProductName"></InputText>
<ValidationMessage For="@(() => selectedProduct.ProductName)" />
<label for="productDescription">Description:</label>
<InputText name="productDescription" @bind-Value="selectedProduct .ProductDescription"></InputText>
<ValidationMessage For="@(() => selectedProduct.ProductDescription)" />
<label for="additionalInformation">Additional Information:</label>
<InputText name="additionalInformation" @bind-Value="selectedProduct.AdditionalInformation"></InputText>
<ValidationMessage For="@(() => selectedProduct.AdditionalInformation)" />
<label for="price">Price:</label>
<InputText name="price" @bind-Value="selectedProduct.ProductPrice"></InputText>
<ValidationMessage For="@(() => selectedProduct.ProductPrice)" />
<label for="auditComments">Comments:</label>
<InputText name="auditComments" @bind-Value="auditProduct.Comments"></InputText>
<ValidationMessage For="@(() => auditProduct.Comments)" />
<button type="submit" class="btn-primary">Save</button>
<button type="submit" class="btn-secondary" @onclick="HandleCancel">Cancel</button>
</div>
</EditForm>
It appears that you are attempting to add validation to your audit table's "comments" column, however the validation is not operating. It appears that you also wish to validate the auditProduct model while using the DataAnnotationsValidator component to validate the selectedProduct model.
You must create a DataAnnotationsValidator component and give the auditProduct model to the EditForm component separately in order to add validation for it.