Does that help You should use view models. Those are classes which are specifically designed to meet the requirements of a view. Controller actions should take/pass only view models to views and never your domain models. So you will have two controller actions, one for inserting and one for editing, and two corresponding view models with their respective validation rules.
How to check if any item is being edited in the QTreeView or not?
wish of those help The item which is currently being edited most likely has some kind of property to identify it (look it up in the database). Therefore, you need to get that property so you can exclude that when you are searching the database for duplicate tags. Here is how to do that in your custom validation class. I am making the assumption the identifier is named TrainerId:
public class UrlTagValidationAttribute : ValidationAttribute
protected override ValidationResult IsValid(object value, ValidationContext context)
string tag = value as string;
return new ValidationResult("URL Tag is required.");
var currentTrainer = validationContext.ObjectInstance
if (currentTrainer == null)
// What do you want to do? You cannot always return an error
// because another type could be using this custom validation.
// Or you can return an error. Depends on your requirements and
// and usage.
using(var dbContext = new OnBoard101Entities())
if(dbContext.TrainerDetails.Any(td => td.Tag == tag && td.TrainerId !=
return new ValidationResult("This URL Tag is not available. Please enter a different one.");