0

I have two tables, Campaign and Advert with a one to many relationship. During Advert creation, the user selects a pre-defined Campaign to which the Advert will belong. A Campaign has an RRP money field and the Advert has a SalePrice money field. What I'm after is a way to ensure that the submitted Advert.SalePrice is >= the chosen Campaigns RRP.

Can this be done in the model? Something along the lines of this in the Advert_Validation? Is it even possible to fill the values of a Range with method calls?

[Range(0, getCampaignRRP(), ErrorMessage = "Value must be equal or greater than the Campaign RRP")]
public double SalePrice { get; set; }

Or do I need to check at the Controller level? All help appreciated!

Thanks all,

Jay

2 Answers 2

2

You can use the new Remote attribute. Basically it calls an action and returns true or false. Here's a link to an example.

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

Comments

0

You can inherit the RangeAttribute class and use that instead.

public class MyRange: RangeAttribute
    {
        public override bool IsValid(object value)
        {
            //Your validation here.
            return MyValidateRange(value, 0, getCampaignRRP());
        }
    }

[MyRange(0, 0, ErrorMessage = "Value must be equal or greater than the Campaign RRP")]
public double SalePrice { 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.