Client side validation in a Grid for a SfDropDownList when adding a new record.

My app uses a database first approach as the database already exists. Thus the models are created when the database is updated. Any validation changes in the model will be overridden when the database is updated. 


My question is, what is the best way of ensuring that a value is selected (value required) when using a  SfDropDownList on the client-side, without having to add validations in the model? 


My code is as follows: 

    <GridColumn Field="IncidentCategoryNavigation.Description" HeaderText="Description">

               <EditTemplate>

                    <SfDropDownList TItem="DataAccess.Models.IncidentCategory" TValue="int?" DataSource="@dataCatList" CssClass="@Validate" Placeholder="Select..."

                                @bind-Value="@((context as DataAccess.Models.IncidentType).IncidentCategory)" ValidationRules=@(new ValidationRules{Required=true})>

                        <DropDownListFieldSettings Text="Description" Value="Id">

                        </DropDownListFieldSettings>

                    </SfDropDownList>

                </EditTemplate>

            </GridColumn>



1 Reply

NP Naveen Palanivel Syncfusion Team May 26, 2022 11:22 AM UTC

Hi Fouche Burgers,


Greetings from Syncfusion Support.


Query: “Client side validation in a Grid for a SfDropDownList when adding a new record”


We have analyzed your query and  we suggest you to achieve your requirement by defining the ValidationRules property of GridColumn to perform validation without adding validations in the model. We have already detailly discussed about  this topic in our UG documentation. Kindly refer the documentation link shared.


Refer our UG documentation for your reference :

https://blazor.syncfusion.com/documentation/datagrid/column-validation


Please get back to us if you have further queries.


Regards,

Naveen Palanivel.


Loader.
Up arrow icon