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.

Friday, November 23, 2012

Thursday, November 22, 2012

Brief introduction to MVC 3 partial views

Here's a brief and to the point introduction to MVC 3 partial views by Microsoft's Rachel Appel:

http://rachelappel.com/razor/partial-views-in-asp-net-mvc-3-w-the-razor-view-engine/

The introduction covers in less than 10 minutes the following topics:

  • What is a partial view and when should I use it?
  • Rendering partial views
  • Creating a partial view
  • Sharing Data between views and partial views

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)...

Monday, November 19, 2012

HOW TO: query many-to-many relations in EF 4


While working with Entity Framework I found my self a bit lost while working with many-to-many relations, as I expect that a class should exist to represent the many-to-many relation table, but in fact, it doesn't exist. So how on earth do you make a query that intends to use the many-to-many relation?...

The answer come from the usual suspect, her's the link at StackOverflow:

http://stackoverflow.com/questions/553918/entity-framework-and-many-to-many-queries-unusable