0

I have model based on existing database and I have written metadata class and custom attribute class, Now I want to convert all custom attribute logic into Jquery or Javascript custom function, Please guide me simple or any available free tool for the same.

4
  • Are you trying to create custom validators? Commented May 18, 2013 at 23:13
  • can't you just use jquery ajax to validate with your custom attributes on the server side ? Commented May 18, 2013 at 23:26
  • @rcdmk : yes, i am trying to create custom validation client site. based on server side custom validaton. Commented May 19, 2013 at 0:00
  • @ScottSelby: thanks, that's also a good idea to to use same logic both side, but as per my current requirement i want to generate same logic to client site, based on server site. Commented May 19, 2013 at 0:02

4 Answers 4

1

rcdmk and Scott Selby have provided excellent resources for how to implement the IClientValidatable interface to integrate with jquery unobtrusive validation. As an alternative, if you don't want to maintain javascript versions of your validation logic, you could use the RemoteAttribute class to instruct the unobtrusive validation to perform an ajax request to validate the data (in fact in some cases this would be the only proper way to validate something - such as username availability).

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

Comments

1

To this moment, there's not a tool for converting custom validator in c# to custom client side validator in JavaScript [that I know of].

I advice you to look for custom validators already built on the web, like http://foolproof.codeplex.com/. Some of them may have what you need and if you can't find one that suits your requirements, follow some tutorials on how to build your own and, maybe, start your own open source project. Since you needed it, others may need it too.

Some tutorials on how to build your own custom validators may get you where you want:

And this is one of my favorite references:

With all this in hand I'm sure you will succeed in create your own client side validators.

Comments

1

You should definitely look at unobtrusive validation in MVC. It adapts MVC to work with Jquery and Jquery validate plugins using data attributes within HTML markup. Once you add a Custom Validation Attribute you must also inherit and implement IClientValidatable. See the following links for more information.

http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-validation.html

http://www.codeproject.com/Articles/275056/Custom-Client-Side-Validation-in-ASP-NET-MVC3

Comments

0

I don't know what your requirements are for your validation , but jQuery validate plugin should handle it. It validates for a lot of common needs automatically (phone number, number, empty text, email) it is also very easy to add custom validation if needed.

2 Comments

Those all custom logic . :-(
Well, since you have custom logic in your attributes, you will have to write custom logic in JS. There's no automagically conversion between server-side and client-side code

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.