Use CustomeValidationAttribute.
First, decorate your property with [CustomValidationAttribute], specifying a validation method. E.g.
[CustomValidation(typeof(YourModel), nameof(ValidateEmployeeCode))]
public string EmployeeCode { get; set; }
ValidateEmployeeCode must by public, static, return ValidationResult, and accept an object as the first parameter, or the concrete type of the property being validated. It can also accept ValidationContext as the second parameter, which has useful properties such as the instance being validated and the display name of the property.
The method then checks based on the condition, if the value is empty or not, and return a ValidationResult.Success or a new ValidationResult with an error message, which is displayed to the user with the Html.ValidationMessageFor() call in the view. You can use the value of the record ID as a flag to know if it's a new record or an updated record.
[RequiredIf]attribute)