Unplanned
Last Updated: 11 Jun 2021 05:56 by ADMIN
Eyup
Created on: 11 Jun 2021 05:54
Category: TextBox
Type: Feature Request
3
Utilize the DataType data annotation in the Razor page

Data Model

[Required]
[StringLength(128)]
[DisplayName("Password")]
[DataType(DataType.Password)]
public string UserPassword { get; set; }
Razor HTML
<div class="form-group">
  <kendo-textbox name="UserPassword" type="password"> <!-HOW to use DataType Annotation here? -- >
      <textbox-label content="@Html.DisplayNameFor(m=>m.UserPassword)" floating="true" />
   </kendo-textbox>
</div>
This scenario is working for a regular <input asp-for="FieldName"/> so it also should work for Telerik TextBox widget as well.

 

The solution below can be used as a workaround for the time being:

@{ Dictionary<string, string> fieldTypes = new Dictionary<string, string>();
    var properties = typeof(TestModel).GetProperties();
    foreach (var property in properties)
    {
        var dataTypeAttributes = property.GetCustomAttributes(
            typeof(System.ComponentModel.DataAnnotations.DataTypeAttribute), false);
        if (dataTypeAttributes.Length > 0)
        {
            var attribute = dataTypeAttributes[0] as
        System.ComponentModel.DataAnnotations.DataTypeAttribute;
            var dataType = (System.ComponentModel.DataAnnotations.DataType)attribute.DataType;
            fieldTypes[property.Name] = dataType.ToString().ToLowerInvariant();
        }
        else
        {
            fieldTypes[property.Name] = null;
        }
    } }
<form id="mainForm" kendo-validator="true">
    <kendo-textbox for="UserPassword" type="@fieldTypes["UserPassword"]">
        <textbox-label content="@Html.DisplayNameFor(m=>m.UserPassword)" floating="true" />
    </kendo-textbox>
</form>
<script>
    $(document).ready(function () {
        var validator = $("#mainForm").data("kendoValidator");
    });
</script
0 comments