0

I'm using Kendo UI 2013.2.716, specifically KendoGrid, C#, Visual Studio 2010, I need to change the globalization of the message "The field X must be a number." as seen in the image and put it in another language. The field x must be a number text.

If I inspect the element in Chrome I see: enter image description here

I tried doing this:

ViewModel

namespace Test.Models
{
   public class TestModel 
   {
     ...
     [DisplayName("Pos")]        
     [IsNumberAttribute(ErrorMessage = "Ingrese un número.")]
     public int Pos { get; set; }
   }
}

namespace Test.Models.CustomValidator
{
    [AttributeUsage(AttributeTargets.Property)]
    public class IsNumberAttribute : ValidationAttribute
    {
        public override bool IsValid(object value)
        {
            try
            {
                int numeroTemp;
                bool esNumero = int.TryParse((string)value, out numeroTemp);
                return esNumero;
            }
            catch (Exception)
            {
                return base.IsValid(value);
            }
        }
    }    
}

But it did not work, still in English :(

In my View I have this:

@(Html.Kendo().Grid<Test.Models.TestModel>(Model)
        .Name("titulo")
        .Columns(columns =>
        {
            ...                
            columns.Bound("Pos").Filterable(false);
            columns.Bound("Edad").Title("Edad").ClientTemplate("#=window.TestMantenedor.Valida(edad)#").Width(500);
        })
        .ToolBar(toolbar =>
        {
            toolbar.Create().Text("Agregar");
            toolbar.Save().SaveText("Modificar").CancelText("Cancelar");
        })
        .Editable(editable =>
        {
            editable.DisplayDeleteConfirmation(false);
            editable.Mode(GridEditMode.InCell);
        })
        .Scrollable()                      
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(20)
            .Batch(true)
            .Model(model =>
            {
                ...
                model.Field(p => p.Edad).DefaultValue(true);
            })
            .Create("Create", "Test", new { id = id })               
            .Events(events => events.Error("error_handler"))
            .Events(events => events.RequestEnd("success_handler"))
        )
        .Filterable(filterable => filterable.Messages(messages =>
            {
                messages.Info("Mostrar plantillas en estado");
                messages.Filter("Filtrar");
                messages.Clear("Borrar");
                messages.IsTrue("Valido");
                messages.IsFalse("No valido");
            })
        )
        .Pageable(p => p
            .Messages(m => m
            .Display("Mostrando {0}-{1} de {2} registros")
            .Empty("No se encontraron registros")
            .First("Ir a la primera página")
            .Last("Ir a la última página")
            .Next("Ir a la página siguiente")
            .Previous("Ir a la página anterior")
            )
        )
)

Any help?

Hernaldo Gonzalez
  • 1,977
  • 1
  • 21
  • 32

1 Answers1

0

Finally, after 3 days trying a lot of stuff, also try the solutions of

How to change 'data-val-number' message validation in MVC while it is generated by @Html helper

@(Html.Kendo().Grid<Test.TestModel>(Model)
        .Name("listado")
        .Columns(columns =>
        {
          columns.Bound("idElementColumn").Filterable(false);
          ...
        }

And at least, in the end of View I put:

<script type="text/javascript">
        $("#listado").on("click", function (e) {
            $(".k-grid #idElementColumn").attr('data-val-number', 'Ingrese un número.');
        });    
</script>
Community
  • 1
  • 1
Hernaldo Gonzalez
  • 1,977
  • 1
  • 21
  • 32