×
Get in touch

Get in touch with Binary

Binary Studio website uses cookies to enhance your browsing experience. By continuing to use our site, you agree to our Privacy Policy and use of cookies.

Learn more more arrow
Agree
Binary Studio 09.09.2009

Using jQuery with ASP.NET MVC


This is an article from the ASP.NET MVC software development series. This article describes one method of performing validation in an ASP.NET MVC application. In this tutorial, you learn how to move your validation logic out of your controllers and into a separate layer.

As you know, jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating and Ajax interactions for rapid web-development (asp.net mvc software development).

jQuery - part of ASP.NET MVC

Now jQuery is part of ASP.NET MVC. So we don’t have any barriers for using that technology in client side. In some of web-applications we develop we have to get much data from client. In one of our projects we had a table with mathematical formulas and parameters, which client can change. It looks like this:

2

We decided to make it with jQuery.

First of all we have to add jQuery library to our application. We put following code to the Sate.Master:

1

The next thing we did was adding jQuery code to the page:

Back on the server side of things, we're going to add a new action to the controller. In action result type should be JsonResult (in that way we get data from server in client side) and we should return our data in Data property of JsonResult object.

So now we have jQuery behavior in our project. When client writes new data in any textbox, result formulas will change without postback (it is very good for a user).

I hope it will be of some help!

ASP.NET MVC jQuery References:

http://www.asp.net/mvc/

http://jquery.com/

http://www.chadmyers.com/Blog/archive/2007/12/13/using-jquery-with-asp.net-mvc.aspx

 

Artyom G,

.Net team, Binary Studio