Required Foreign Key Column

2 posts, 0 answers
  1. Graeme
    Graeme avatar
    5 posts
    Member since:
    Jun 2015

    Posted 15 Jul 2015 Link to this post

    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.



  2. Plamen Lazarov
    Plamen Lazarov avatar
    135 posts

    Posted 17 Jul 2015 Link to this post

    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

    Plamen Lazarov
    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
Back to Top