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

Custom Validation example for Telerik ASP.NET Core Grid

1 Answer 341 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 18 Jul 2018, 08:35 AM

Hi,

 

The Telerik ASP.NET Core Grid custom validation example (https://demos.telerik.com/aspnet-core/grid/editing-custom-validation) defines a custom validation rule via the CustomValidationProductViewModel model and the productnamevalidation function.

However, the CustomValidationProductViewModel is not visible on the page. Could you please make the model available?

Kind regards

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 20 Jul 2018, 10:15 AM
Hello Mark,

Thank you for the feedback. 

Below you can see the definition of the model for the custom validation example.

using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
 
namespace Kendo.Mvc.Examples.Models
{
    public class CustomValidationProductViewModel
    {
        public int ProductID { get; set; }
 
        [Required]
        [CustomProductNameValidation(ErrorMessage = "ProductName should start with capital letter")]
        public string ProductName { get; set; }
 
        [DataType(DataType.Currency)]
        public decimal UnitPrice { get; set; }
    }
 
    public class CustomProductNameValidationAttribute : ValidationAttribute  //, IClientModelValidator
    {      
        public override bool IsValid(object value)
        {
            var productName = (string)value;
            if (!string.IsNullOrEmpty(productName))
            {
                return Regex.IsMatch(productName, "^[A-Z]");
            }
            return true;
        }
 
    }
}


With that said, if you would like to try the demos locally you can download the archive containing the examples. The demos are located in the \wrappers\aspnetcore\Examples\ subfolder.

Regards,
Viktor Tachev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or