Click here to Skip to main content
15,885,985 members
Articles / Programming Languages / C# 4.0

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

Rate me:
Please Sign up or sign in to vote.
4.66/5 (11 votes)
22 Apr 2012CPOL6 min read 80.4K   4K   35  
Here is a simple CRUD on the MVC music store using backbone.
@model RazorApp.Models.Album
<script type="text/javascript">
    $(function () {
        $('#AlbumArtUrl').width(340);
        $('#valSum').hide();
        $('#btnCancel').click(function () {
            $("#albumEditDialog").dialog("close");
            $('#storeManagerResults').trigger("reloadGrid");
            return false;
        });
        $('#myForm').bind('invalid-form.validate', function (error, element) {
            $('#valSum').show("slow");
            return false;
        });
        var msg = '@ViewBag.Message';
        if (msg != '') {
            $('#update-message-disp').show("slow");
        } else {
            $('#update-message-disp').hide();
        }
    });
</script>
<script type="text/javascript">
    $(function () {
        $("input:submit, a, input:button", ".styler").button();
        $("#GenreId, #ArtistId").chosen();
        $('#Title, #Price, #AlbumArtUrl').addClass("textbox");
    });
</script>
@if (!ViewData.ModelState.IsValid)
{
    <script type="text/javascript">
        $(function () {
            $('#valSum').show("slow");
        });
    </script>
}

@using (Ajax.BeginForm("DoEditAlbum", new AjaxOptions { UpdateTargetId = "albumEdit" }))
{
    <fieldset class="ui-widget">
            <legend class="ui-state-legend-default ui-corner-top ui-corner-bottom">Edit Album :
                @Model.Title </legend> <br />
            <div id="valSum" class="ui-state-error ui-corner-all" style="padding: 0 .7em; width: 500px">
                <p>
                    <span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
                    <strong>Please correct these Errors</strong> @Html.ValidationSummary(false, "")</p>
            </div>
            <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>Insert Complete!!</strong><br />
                @ViewBag.Message
            </p>
        </div>
            <table id="">
                <tr>
                    <td>
                        <div class="editor-label">
                            @Html.HiddenFor(model => model.AlbumId)
                            @Html.LabelFor(model => model.GenreId, "Genre")
                        </div>
                        <div class="editor-field">
                            @Html.CoolDropDownListFor(model => model.GenreId, (SelectList)ViewBag.GenreId, true)
                        </div>
                    </td>
                    <td>
                        <div class="editor-label">
                            @Html.LabelFor(model => model.ArtistId, "Artist")
                        </div>
                        <div class="editor-field">
                            @Html.CoolDropDownListFor(model => model.ArtistId, (SelectList)ViewBag.ArtistId, true)
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="editor-label">
                            @Html.LabelFor(model => model.Title)
                        </div>
                        <div class="editor-field">
                            @Html.EditorFor(model => model.Title)
                        </div>
                    </td>
                    <td>
                        <div class="editor-label">
                            @Html.LabelFor(model => model.Price)
                        </div>
                        <div class="editor-field">
                            @Html.EditorFor(model => model.Price)
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <div class="editor-label">
                            @Html.LabelFor(model => model.AlbumArtUrl)
                        </div>
                        <div class="editor-field">
                            @Html.EditorFor(model => model.AlbumArtUrl)
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan = "2">
                        <input type="submit" value="Save" /> | <input type ="button" id = "btnCancel" value="Cancel" />
                    </td>
                </tr>
            </table>
        </fieldset>
}

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)


Written By
Software Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions