When using MVC Foolproof Validation
, is it possible to have a custom validation asynchronous
? I am wanting to retrieve an object from a DbSet
in a custom validation, to check if the object exists.
Is this possible? If not, is there a work around that achieves the same result?
Here is my code:
public class RequiredThumbnailAssetId : ModelAwareValidationAttribute
{
static RequiredThumbnailAssetId() { Register.Attribute(typeof(RequiredThumbnailAssetId)); }
public async override Task<bool> IsValid(object value, object container)
{
var model = (IGridViewItemWithAssetId)container;
if (model.thumbnailAssetId <= 0)
{
return false;
}
CanFindLocationDatabaseContext db = new CanFindLocationDatabaseContext();
Asset asset = await db.assets.FindAsync(model.thumbnailAssetId);
if (asset == null)
{
return false;
}
return true;
}
}
Here is the error that I am getting:
'CanFindLocation.CustomValidations.RequiredThumbnailAssetId.IsValid(object, object)': return type must be 'bool' to match overridden member 'Foolproof.ModelAwareValidationAttribute.IsValid(object, object)'
Thanks in advance.