jQuery Unobtrusive Ajax in ASP.NET MVC 3
Let’s talk today a little bit about very useful and easy to use in MVC 3 jQuery library called jQuery.Ajax.Unobtrusive. With a MVC 1 and 2 Microsoft provide library to work with AJAX requests. Already then was created Ajax helper to render form and link with unobtrusive parameters for AJAX requests. But these parameters were handled only by MicrosoftMvcAjax JavaScript library. The problem is that this library is what a lot of users doesn’t want it to use. Instead, they prefer to use jQuery – “write less, do more”. With MVC 3 situation become better. Microsoft released jQuery.Ajax.Unotrusive JavaScript library. I will show you how easy we can make AJAX form (or action link) with Ajax helper and the JavaScript library.
Read more...
ASP .NET MVC 3: JQuery validation and Data Annotation or Unobtrusive Client Validation
In previous article I’ve show you how to validate form using jQuery validation plugin and view model Data Annotations. With MVC 3 Microsoft have implemented jQuery validation referring to standard Data Annotation attributes. Let me show you how to use it in simple example.
Read more...
Using jQuery to submit ASP .NET MVC form
Simplest, easier and nice method to submit MVC form using jQuery AJAX:
$("formMapMarker").submit(function(e) {
if ($("formMapMarker").valid()) {
$.post($(this).attr("action"), $(this).serialize());
}
e.preventDefault();
});
Read more...
All about MVC validation with jQuery or Validate model with Data Annotations using jQuery
There are a lot of articles about validation in MVC. I’ve tried all of them and tried to find optimal and nice solution to validate model defined with Entity Framework, using Data Annotation attributes and have client-side validation related to these attributes using jQuery validation plugin. Too much? :) I don’t think so. Here is the solution.
Read more...
External links in new window using jQuery
Instead of using each time attribute target="_blank" for hyperlinks you can use jQuery.
$().ready(function () {
$('a[href^=http]').addClass('external').attr('target', '_blank');
});
On loaded page jQuery selects all links on the page which begins with 'http', applies class "external" and adds attribute "target=_blank". Example any external link on this webpage. Is it not simple and nice? BTW, Strict HTML don’t allow using target=_blank attribute.