Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Simple CRUD Using Backbone.js in ASP.NET MVC Razor

, 22 Apr 2012
Here is a simple CRUD on the MVC music store using backbone.
RazorApp.zip
RazorApp
App_Data
ASPNETDB.MDF
aspnetdb_log.ldf
MvcMusicStore.sdf
bin
EntityFramework.dll
RazorApp.dll
RazorApp.pdb
Content
images
admin-privilege-icon.png
chosen-sprite.png
Home-icon.png
home-showcase.png
img_logo.gif
logo.png
placeholder.gif
shopping-cart-icon.png
textbox_bg.jpg
ui-bg_flat_55_999999_40x100.png
ui-bg_flat_75_aaaaaa_40x100.png
ui-bg_glass_45_0078ae_1x400.png
ui-bg_glass_55_f8da4e_1x400.png
ui-bg_glass_75_79c9ec_1x400.png
ui-bg_gloss-wave_45_e14f1c_500x100.png
ui-bg_gloss-wave_50_6eac2c_500x100.png
ui-bg_gloss-wave_75_2191c0_500x100.png
ui-bg_gloss-wave_85_9fda58_500x100.png
ui-bg_inset-hard_100_fcfdfd_1x100.png
ui-icons_0078ae_256x240.png
ui-icons_056b93_256x240.png
ui-icons_d8e7f3_256x240.png
ui-icons_e0fdff_256x240.png
ui-icons_f5e175_256x240.png
ui-icons_f7a50d_256x240.png
ui-icons_fcd113_256x240.png
themes
base
images
ui-bg_flat_0_aaaaaa_40x100.png
ui-bg_flat_75_ffffff_40x100.png
ui-bg_glass_55_fbf9ee_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_glass_75_dadada_1x400.png
ui-bg_glass_75_e6e6e6_1x400.png
ui-bg_glass_95_fef1ec_1x400.png
ui-bg_highlight-soft_75_cccccc_1x100.png
ui-icons_222222_256x240.png
ui-icons_2e83ff_256x240.png
ui-icons_454545_256x240.png
ui-icons_888888_256x240.png
ui-icons_cd0a0a_256x240.png
Controllers
Global.asax
Helper
Models
obj
Debug
DesignTimeResolveAssemblyReferences.cache
DesignTimeResolveAssemblyReferencesInput.cache
RazorApp.dll
RazorApp.pdb
TempPE
Properties
RazorApp.csproj.user
Scripts
i18n
StoreManager
ViewModels
Views
Account
Ajax
Checkout
Home
Shared
ShoppingCart
Store
StoreManager
@model RazorApp.ViewModels.ShoppingCartViewModel
@{
    ViewBag.Title = "Shopping Cart";
}
<script type="text/javascript">
    $(function () {
        var requestUrl = '@Url.Action("GetCart")';

        $("#cartResults").jqGrid({
            url: requestUrl,
            datatype: 'json',
            mtype: 'POST',
            emptyrecords: "No results",
            colNames: ['Album Name', 'Price', 'Quantity', ''],
            colModel: [
                            { name: "Title", width: 350, editable: false, searchoptions: {}, index: "Title" },
                            { name: "Price", width: 100, editable: false, searchoptions: {}, index: "Price" },
                            { name: "Quantity", width: 100, editable: false, searchoptions: {}, index: "Quantity" },
                            { name: 'Delete', width: 140, formatter: deleteFormatter }
                            ],
            pager: $('#cartPager'),
            rowList: [],        // disable page size dropdown
            pgbuttons: false,     // disable page control like next, back button
            viewrecords: false,    // disable current view record text like 'View 1-10 of 100' 
            sortname: 'id',
            sortorder: 'asc',
            loadonce: false,
            sortable: true,
            scrollrows: true,
            height: 300,
            pgtext: null,
            hoverrows: false,
            footerrow: true,
            userDataOnFooter: true,
            emptyDataText: "Your Cart is Empty",
            gridComplete: function () {
                if ($('#cartResults').getGridParam('records') == 0) {
                    //var noRecords = "<div class=\"loading ui-state-default ui-state-active\" id=\"load_forSteps_Home_table\" style=\"left: 0px; top: 48px; display: block;\"><div class=\"field-validation-error\" style=\"padding:12px 4px 4px 4px\">Your Cart is Empty.</div></div>";
                    var noRecords = "<div class=\"customloading\" id=\"load_cart_Results\" style=\"left: 0px; top: 48px; display: block;\"><div class=\"ui-state-highlight ui-corner-all\" style=\"margin-top: 20px; padding: 0 .7em;width: 500px;height:200px\">";
                    noRecords += "<p><span class=\"ui-icon ui-icon-info\" style=\"float: left; margin-right: .3em;\"></span><strong>No records</strong><br /><br /><br />";
                    noRecords += "Your Cart is Empty. Select albums to your cart.</p></div></div>";

                    $('#lui_cartResults', '.ui-jqgrid').after($(noRecords));
                    $('#btnCheckOut').hide();
                } $("button").button();
                $(".RemoveLink").click(function () {
                    // Get the id from the link
                    var recordToDelete = $(this).attr("data-id");
                    if (recordToDelete != '') {
                        // Perform the ajax post
                        $.post("/ShoppingCart/RemoveFromCart", { "id": recordToDelete },
                    function (data) {
                        $('p', '#update-message-disp').append(data.Message);
                        $('#update-message-disp').show("slow");
                        $('#cartResults').trigger("reloadGrid");
                        return false;
                    });
                    }
                });
            }
        });

        function deleteFormatter(cellvalue, options, rowObject) {
            return "<button  class=\"RemoveLink\" data-id = \"" + options.rowId + "\">Remove from Cart</button>";
        }

        $('#update-message-disp').hide();
    });
</script>
<div class="styler">
    <fieldset class="ui-widget">
        <legend class="ui-state-legend-default ui-corner-top ui-corner-bottom">Review Your Cart</legend>
        <div id="update-message-disp" class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;width: 500px">
            <p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span><strong>Cart modified</strong><br />
            </p>
        </div>
        <br />
        <table id="cartResults">
        </table>
        <div id="cartPager">
        </div>
    </fieldset>
    @Html.ActionLink("Checkout>>", "AddressAndPayment", "Checkout", null, new { id = "btnCheckOut"})
</div>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Baliah Senthilkumar
Software Developer
United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140921.1 | Last Updated 22 Apr 2012
Article Copyright 2012 by Baliah Senthilkumar
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid