Thanks to everyone who attended my webinar today on jQuery and ASP.NET MVC. I hope I was able to show you how awesome these two technologies are and how they can work together. There are again lots of requests for both the video and source code: the video has been posted and you can also download the source code attached to this post.
Question and Answer
Here are questions that some of your peers asked during today’s webinar:
First, there was some confusion around the term AJAX. It actually refers to two things:
- AJAX stands for Asynchronous JavaScript and XML and it is a group of technologies used for interacting with the server on the client side. Technically, XML is not required, and it doesn’t have to be asynchronous, but the concept is the same: to interact with the server without reloading the page.
- Microsoft’s ASP.NET AJAX is a client-side framework which implements the AJAX group of technologies.
How do I create a website without ViewState? Where do I store changes?
The concept of ViewState was Microsoft’s attempt to help ease the conversion from desktop development, which is stateful, to web development, which is stateless. I have built quite a few websites now in ASP.NET MVC, some of them ranging in the hundreds of Actions and Views, and I do not miss ViewState. The one instance I see some sort of state being useful in an application however is a multi-page shopping cart, and you can approach this in several ways:
- Have the entire cart rendered on the client and use a client-side framework like jQuery to perform the visual transitions and communicate with the server. I prefer this method.
- Store information on each round trip to the database with the user’s session. This requires a bit of extra work however to get the information, and make sure it is cleaned up when it’s no longer needed.
Is ViewData in ASP.NET MVC the same thing as ViewState in ASP.NET Web Forms?
ViewState and ViewData are two very different things. ViewState is used to emulate state in the stateless world of ASP.NET Web Forms. ViewData is used to pass data from an MVC Action to an MVC View. Once the View has been rendered, the ViewData is no longer available.
I have an existing app with classic JavaScript, can i use jQuery alongside going forward?
Absolutely, jQuery and JavaScript can be used alongside each other. In fact, they can interact somewhat with each other as well. For example, I can make a core JavaScript alert(); call while setting the message to something from jQuery: alert($(‘field#id’).val());. Be sure that you don’t pollute the global namespace however, this can cause major issues.
Can i use jQuery to connect to SQL Server?
Since jQuery is a client-side technology, it doesn’t connect to SQL Server directly. You can however call an Action on the server that will perform data tasks and return the results to you. See the Search demo in the sample code.
Can I use Wijmo widgets and jQuery together?
Yes, the Wijmo widgets are in fact built on top of jQuery.
Can I use the DevExpress controls in ASP.NET MVC?
The DevExpress ASP.NET Web Forms controls will not work in ASP.NET MVC since they require ViewState. We currently have a set of 5 ASP.NET MVC extensions, and will have roughly 20 additional extensions in our next release to our Universal, Enterprise, and ASP.NET Edition customers.