Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Thursday, November 29, 2012

HOWTO trigger MVC 3 validation from jQuery


Have you ever wonder how to trigger de MVC 3 form validations from jQuery? ... well, I've done it, and belive me, I spend more than an hour finding out how to. So, the answer is pretty simple: to trigger the validators do something like
$('#MyForm').validate().form();
And for checking if the all the validations get passed look for something like
var isMyFormValid = $('#MyForm').validate().valid();
That's all.

(The answer was found thanks to the ASP.NET forums)

Monday, November 26, 2012

Test your javascript code online


Some time ago thanks to an answer at StackOverflow I discovered an amazing web service called jsfiddle. Basically it allows you to test your JavaScript code online with the option to make use of some of the most popular frameworks out there (like jQuery, Mootools, YUI, Dojo, etc..), and if you need so, you can share your "fiddles" too.

An excellent tool that always come handy.

Wednesday, November 21, 2012

HOW TO: embed MVC 3 Razor code inside a javascript block

This one is actually a kind of weird trick that's is required (as far as I know) in the current version of MVC for embedding razor code inside a javascript block. It's very possible that you find yourself wondering how to accomplish this when you are begining with MVC and razor:

http://stackoverflow.com/questions/4204669/asp-net-mvc3-rc-razor-views-syntax-for-embedding-code-inside-javascript-bloc

P.S. I'm not sure if this is still necessary in the current version of MVC (MVC 4 ath the time of this writing)...