4 Answers, 1 is accepted
Hello, Suresh,
You can use DataAnnotation attributes. The Kendo UI Validator creates validation rules based on the unobtrusive HTML attributes. Those unobtrusive attributes are generated by ASP.NET MVC, based on the DataAnnotations applied to the Model properties. Here is an example:
[StringLength(3, ErrorMessage = "Name cannot be longer than 3 characters.")]
public string ProductName { get; set; }
As per the EditorViewData, this option has to be used only when you would like to pass additional data to the editor template. In the current case, you would have access to a variable "maxLength" in the editor template via the ViewData. It will not apply any validation.
Let me know if further assistance is needed.
Kind Regards,
Anton Mironov
Progress Telerik
Thank You Anton!
Adding data annotations helps with validation .But , what i was looking was to prevent the user from entering characters more than the limit , like we have the maxlength for TextBox controls.
Added a editor template like -@Html.Kendo().TextBoxFor(x => x).HtmlAttributes(new { maxLength = ViewData["maxLength"] })
and binding the same as editor template in grid- EditorTemplateName("_EditTextBox").EditorViewData(new { maxlength = 50 });
This prevents the user from entering more than 50 characters in grid incell edit mode .
Its working but not sure if it's the right approach.
Hi, Suresh,
Regards,
Anton Mironov
Progress Telerik