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

How validated filed when create new record

2 Answers 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mohammed
Top achievements
Rank 1
Mohammed asked on 31 Oct 2019, 09:42 AM

how to validate the required field

which i define it the class as Required 

        example 
        [Required]
        public string Title { get; set; }
        [Required]
        public string Description { get; set; }

when i create new Record in grid asp.net Core

then i press Save button directly catch the controller with out any validation 

there is event in the grid 

.Events(e => e.Error("error"))

<script>
    function error(e) {

        console.log(e);
        if (e.errors) {
            var message = "Errors: \n";
            $.each(e.errors, function (key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function () {
                        message += this + "\n";
                    });
                }
            });
            alert(message);
        }
    };

</script>
any help please 

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Mohammed
Top achievements
Rank 1
answered on 04 Nov 2019, 02:53 AM
any help please
0
Alex Hajigeorgieva
Telerik team
answered on 05 Nov 2019, 07:15 AM

Hi, Mohammed,

From the provided screenshot is visible that a custom popup and custom editors are used. 

If you use the EditorFor() syntax, validation attributes will be added out of the box:

@model APICore.Models.Student

<div class="k-edit-label">
    @Html.LabelFor(m=>m.FirstName)
</div>
<div class="k-edit-field">
    @Html.EditorFor(m => m.FirstName)
</div>

In this case, the editor corresponding to the field type will be used, if it is available in the ~Views\Shared\EditorTemplates\String.cshtml

@model string

@Html.Kendo().TextBoxFor(x=>x)

If it is not available or you wish to use something else, then you can add the required attribute yourself.

Let us know in case you need further assistance. If you do, please provide the model class fields that you wish to validate as well as the popup view so we can provide you with concrete answers to your questions.

Kind Regards,
Alex Hajigeorgieva
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Mohammed
Top achievements
Rank 1
Answers by
Mohammed
Top achievements
Rank 1
Alex Hajigeorgieva
Telerik team
Share this question
or