Home » Asp.netRSS

Carousel on ASP.NET MVC page

Looking for tips how to code.


Web page has JQuery based carousel that presents first pages of books. Clicking on a book image is supposed to update book detail fields that are located under carousel section.


What is the best way to refresh book details section? Should I use ajax?

Some links with examples would be appreciated.
 

 

1 Answer Found

 

Answer 1

One option it to use an ajax  call using jquery. I don't know what jquery  carrousel extension you are using or what event you can bind on but assume that the name of the event is called click and that the control is called carrousel and that you have bookscontroller with an action GetDescription, it will all look something like this:

<script type="text/javascript" language="javascript">
    $().ready(function () {
        $("#carrousel").pictureClick(onClick);
    });

    function onClick() {
        var bookId = /* here you need to get the id of the book  somehow */;
        $.ajax({
            async: false,
            type: 'POST',
            url: '<%: Url.Action("GetDescription", "BooksController") %>',
            data: 'bookId=' + bookId,
            success: function(data) {
                /* do something with the return book description */
            }
        });
    }
</script>

In in the GetDescription action of the BooksController you return a JsonResult. This is more or less roughly what you need to do...

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter