[EN][#ASPNETMVC] Unobtrusive validation with jQuery on MVC

Making some workshop for my company trainer program who we will release soon i was reviewing some old code that i don´t publish on the blog.

One of this is the use os unobtrusive validation using jQuery on ASP.NET MVC 4 app with Razor engine.

What we want

In my app i want to validate, when a user is registering is name and name of league, if the user name exists, if the league name exists and if the pair nameleage-passleague is correct.

Post will focus only on the subject league and password league. This is the part of the form for that.

What we do

At the bottom of the page i have a @section Scripts created on my shared folder in the _Layout.csthml:

And the code of the @section Scripts before editing is:

Then it´s time to call functions that validates in the backend the data. For this we use jQuery and edit the $(document).ready(function () {}); like this using ajax jQuery function.

I think that jQuery ajax method is better explained in a hunderd post on internet. The only specific from asp.net mvc is @Url.Action("LigaCreada") that provide us the url for the action who validate on the backend. At the first time i have a simple implementation for this action:

Action connect to database an validate if exists the pair leagueName-leaguePassword if any row is loaded we will get true else we´ll get false.

There is a simple resumen of how to use unobtrusive validation with jQuery on aspnet mvc 4 apps.

Comments are closed here.