Asp.Net MVC. Updating user control (Shopping Cart) with Ajax

I want to implement a user control which represents a list of the current items in a user's shopping cart, and which is included from within the a master page.

I want to add a product to the shopping cart; the shopping cart should be automatically updated with an asynchronous call (JavaScript framework is jQuery) when a user adds a product to his or her shopping cart, vice versa the contents should be removable from the shopping cart.

I have it implemented statically, the sessions contents (orders, products) are stored in the database.

I have a ProductsController and a OrderController (shopping cart is basically an order with assigned products and a user id or temporary session id).

With all the different Previews, Betas and the RC, and a lack of a centralized documentation for ASP.NET MVC I find it hard to find proper documentation on this subject.

Could anyone point me to some starting tutorials?

Thanks.

Answers


If I understand the question right you want to be able to call a Controller that calls some business logic in the model to update the shopping cart. If this is correct you want to create a JsonResult Controller Action. You will use jQuery to call this action... I wrote a very simple example of this available at http://www.dev102.com/2008/08/19/jquery-and-the-aspnet-mvc-framework/


What I did in the application I am working on at the moment, to make an action in the shopcart controller (name it getAjaxCart or something obvious) that returns a partial view containing the list of items with the price etc, and put that in the div that you have assigned for the shopping cart. Check out the jquery documentation at http://docs.jquery.com/Ajax/jQuery.ajax .

You can then use $('#shopcart').html(result) in the success part of the javascript call.


Need Your Help

Modifying the java code generated by adding a break line before each new section

java eclipse abstract-syntax-tree line-breaks

how can i add a break line before each new Section in a java source code automatically?. My java source code is generated automatically and it is made of 5 sections. i must create a new java class,...

Arduino/MPU6050/AdafruitMotorShieldV2: script hangs/freezes when turn on motors

arduino-uno motordriver mpu

I'm a newby to robotics and electronics in general, so please don't assume I tried anything you might think is obvious.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.