1

I have a model called Organisation, on the organisation I have a remote validation attribute:

[Required(ErrorMessage = "The organisation name is required")]
    [Remote("NameCheck", "Manage", "Organisations", ErrorMessage="That organisation      already exists")]
    public string Name { get; set; }

This checks that the name of the organisation someone is adding doesn't already exists. If it does then they get an error message saying so.

I'm using a strongly typed view to render the organisation "edit" view. Because someone is editing, I don't want that remote validation to run because of course the organisation will exist.

Is there any way to achieve this? Basically, turn off the remote validation in some way when editing an organisation and have it turned on when creating an organisation.

2
  • 4
    If his users expect British English then it will be Organisation. If they expect American English then it will be Organization. From his consistent spelling, I expect it is the former. Commented Nov 8, 2011 at 16:29
  • John Hartsock, Jared Peless, comments like this could have been useful on english.stackexchange.com but not very helpful in a programming related Q&A site such as StackOverflow. Commented Nov 8, 2011 at 16:40

2 Answers 2

4

You could/SHOULD use different view models for the two views. So for example you will have CreateOrganizationViewModel and UpdateOrganizationViewModel. On the first view model the Name property will be decorated with the remote attribute whereas on the second view model it will not.

Sign up to request clarification or add additional context in comments.

Comments

3
public class BaseOrganizationModel {
  public int ID {get; set;}
}

public class UpdateOrganizationModel : BaseOrganizationModel {
    [Required(ErrorMessage = "The organisation name is required")]
    public string Name { get; set; }

}

public class InsertOrganizationModel : BaseOrganizationModel {
    [Required(ErrorMessage = "The organisation name is required")]
    [Remote("NameCheck", "Manage", "Organisations", ErrorMessage="That organisation      already exists")]
    public string Name { get; set; }

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.