This is a migrated thread and some comments may be shown as answers.

Required Foreign Key Column

1 Answer 310 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Graeme
Top achievements
Rank 1
Graeme asked on 15 Jul 2015, 01:30 PM

I've set up a grid with a required foreign key by creating a copy of the GridForeignKey editor template and adding .HtmlAttributes(new { required="required" }) and applying that editor template to the foreign key column.

This seems to work nicely however the validation message i get on the grid is "ClientID is required". How do i set this up to refer to the required field by its column title rather than the name in the model.

Thanks

Graeme

1 Answer, 1 is accepted

Sort by
0
Plamen Lazarov
Telerik team
answered on 17 Jul 2015, 12:57 PM

Hello Graeme,

In general, the validation of the editors is controlled by the Model DataAnnotation attributes. This is how the validation of ASP.NET MVC works. That being said, the Grid MVC wrapper also honor this approach and retrieve the related information from the model metadata. This is how our online demos are configured. You can further investigate this approach debugging the offline demos part of the UI for ASP.NET MVC bundle.

In short, you will need to decorate the Model field accordingly using the System.ComponentModel.DataAnnotations RequiredAttribute.

If you do not want to use DataAnnotation attributes, then you will need to define define custom messages. Please refer to the following resources which gives more information on this subject. 
  - Defining custom messages
  - Custom validator editing

Regards,
Plamen Lazarov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DropDownList
Asked by
Graeme
Top achievements
Rank 1
Answers by
Plamen Lazarov
Telerik team
Share this question
or