In the part one I’ve shown how to implement the jQuery Accordion on client-side and add some predefined skin. javascript
In the part two the Accordion is implemented in ASP.NET WebForms application, filled with data from database.css
Now, in this blog I will show the same for an ASP.NET MVC application.html
Note: The database table is the same from the part 2.java
I’ve created empty ASP.NET MVC Application.jquery
I’ve added the followingweb
So, I have one HomeController, one Home –> Accordion.aspx View and WebStoreModel.edmx entity model for the WebStore database. It contains only one table.ajax
Then, in the Global.asax file I’ve slightly changed the default route
since I don’t have Index.aspx page, I only have Accordion.aspx page.app
In the HomeController.cs I have the following ActionResult methodasp.net
MyWebStoreEntities() is the entity container name. This way, if we would have more entities inside the model, we can easily retrieve any.ide
You can use LINQ 2 SQL Classes if you want and you will retrieve the data using LINQ statement.
And, the Accordion View code is
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>Note: You can use <%: item.name %> if you have ASP.NET 4.0 which replaces the Html.Encode(item.name) – otherwise, you will need to go with <%= Html.Encode(item.name) %> or Server.HtmlEncode(..).
And that’s it. If you run the web application, the result will be same as in part 2.
Great result in few simple steps! Thats what you get if you use jQuery with ASP.NET ;)!
I hope you like it :).
Regards,
Hajan
YOU CAN DOWNLOAD THE COMPLETE PROJECT (Client-side Implementation + WebForms + MVC) HERE.