I've wrote a Custom Validation for Guid Type Like this:
public class ValidGuidAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
string msg = "please select a device";
ErrorMessage = msg;
var input = Convert.ToString(value);
if (string.IsNullOrEmpty(input) )
{
return false;
}
Guid guid;
if(!Guid.TryParse(input,out guid))
{
return false;
}
if (guid == Guid.Empty)
{
return false;
}
return true;
}
}
and when I inspect element on the browser I have this :
<span class="field-validation-valid" data-valmsg-for="DeviceGroupId" data-valmsg-replace="true"></span>
and when I don't fill that filed and post form , I've got this error Message :
The value 'please select a device' is not valid for device group.
I want just get this :
please select a device
and In ViewModel I have :
[DisplayName("device group"),ValidGuid(ErrorMessage = "please enter")]
public Guid DeviceGroupId { get; set; }

