Remote validation doesn't work in Grid

Hello

I'm trying to use Remote validation, but it doesn't work in Grid.

Here are my view model and Grid definitions. Remote validation for the UserName property should check whether username exists. This validation works fine in other places, but not in the Grid and not in the edit forms loaded via Ajax call.

public class GridItemViewModel
{
    public string Id { get; set; }
    [Required]
    public string LastName { get; set; }
    [Required]
    [Remote(nameof(UsersController.IsValidUsername), "Users", ErrorMessage = "Username exists")]
    public string UserName { get; set; }
}


@(Html.EJ().Grid<GridItemViewModel>("Users")
    .Datasource(Model.DataSource)
    .Columns(cb =>
    {
        cb.Field(m => m.Id).IsPrimaryKey(true).Visible(false).Add();
        cb.Field(m => m.LastName).Add();
        cb.Field(m => m.UserName).Add();
    })
    .EditSettings(e => e.AllowAdding(true).AllowDeleting(true).AllowEditing(true)
        .EditMode(EditMode.Normal))
    .ToolbarSettings(ts => ts.ShowToolbar(true)
        .ToolbarItems(tbi =>
        {
            tbi.AddTool(ToolBarItems.Add);
            tbi.AddTool(ToolBarItems.Edit);
            tbi.AddTool(ToolBarItems.Update);
            tbi.AddTool(ToolBarItems.Cancel);
        }))
)

Screenshot shows that the LastName property is properly validated, but the UserName is not.



I tried with the various EditModes, but it's all the same.
Is it possible to remote validate a property in the grid, using any Edit mode?



1 Reply

KM Kuralarasan Muthusamy Syncfusion Team June 20, 2018 12:44 PM UTC

Hi Tomislav, 

Thanks for contacting Syncfusion support. 

We could see you would like to validate the Grid columns using the Remote attribute of the DataAnnotations. By default, Remote Attribute will trigger the method only if the validation done in the server end. Otherwise, it won’t trigger the method bound to them.  

In our case, Grid has been rendered and its edit forms were validated completely in the client-end. So, we cannot implement this method in the Grid. However, we can validate the Grid in the server-end using the actionBegin event of the Grid. We have already discussed about this topic our kb documentation. So please refer the following kb to achieve your requirement, 


Please let us know whether you need further assistance on this, 

Regards, 
Kuralarasan M. 


Loader.
Up arrow icon