0

I Create this class.

  public class UniqueFileNumber : ValidationAttribute
    {

        private string _LocationFile;

        public override string FormatErrorMessage(string str)
        {
            return ViewRes.ValidationString.Loc_FileNumberExist;
        }

        public override bool IsValid(object value)
        {
            DBEntities _db = EntityFactory.GetEntity();
            string strName = Convert.ToString(value);
            return !_db.Locations.Any(p => p.LocationFile == strName);

        }
    }

and add this attribute to my entity Like that.

[UniqueFileNumber]
public object FileNumber{ get; set; }

The validation work only on the PostBack (Refresh).

It would be fine if it's work on client side too. In my client side , I add that line

<% Html.EnableClientValidation(); %>

What's the problem here.

thanks.

1
  • Can you share the code that makes up your view as well? (Everything looks fine so far.) Commented Mar 14, 2011 at 20:03

2 Answers 2

1

You have to give it the javascript fonction to use for validation...

check out this post from Phil Haacked ASP.NET MVC 2 Custom Validation

A better example for what you have to do since you still need to go on the server, check this post from Brad Wilson Remote Validation with ASP.NET MVC 2

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

2 Comments

merci moi_meme, c'est exactement ce que je voulais :)
@Jean-François: Ça fait plaisir :)
0

One more Remote Validation ASP.NET MVC 2 based on Brad Wilson idea, but used jQuery ajax calls.

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.