Click here to Skip to main content
15,898,134 members
Articles / Web Development / ASP.NET

Using JEditable Plugin as ASP.NET MVC3 jQuery Inline Editor

Rate me:
Please Sign up or sign in to vote.
4.86/5 (48 votes)
24 Jun 2012CPOL17 min read 162K   3.5K   132  
This article describes how you can implement inline editing in an ASP.NET MVC application using the jQuery Jeditable plug-in.
In this article, I will show you a jQuery alternative for content editable - the Jeditable plug-in. I will also explain how you can implement inline editing functionality in an ASP.NET MVC3 application using jQuery.
@model JQueryEditableMVC.Models.Company
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <title>Details</title>
    <script src="/Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script src="/Scripts/jquery.jeditable.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {

            $(".display-label").editable("/Company/UpdateLabel");

            $(".text").editable("/Company/UpdateField",
                        {
                            submitdata: {
                                CompanyId: function () {
                                    return $("#CompanyId").val();
                                },
                                RecordType: "COMPANY"
                            }
                        });

            $(".textarea").editable("/Company/UpdateField",
                                    {
                                        type: 'textarea',
                                        rows: 4,
                                        columns: 10,
                                        cancel: 'Cancel',
                                        submit: 'OK',
                                        submitdata: {
                                            CompanyId: function () {
                                                return $("#CompanyId").val();
                                            },
                                            RecordType: "COMPANY"
                                        }
                                    });

            $(".select").editable("/Company/UpdateField",
                                    {
                                        type: 'select',
                                        data: "{ 'Belgrade': 'Belgrade', 'Paris': 'Paris', 'London': 'London', 'Madrid': 'Madrid' }",
                                        submit : 'OK',
                                        submitdata: {
                                            CompanyId: function () {
                                                return $("#CompanyId").val();
                                            },
                                            RecordType: "COMPANY"
                                        }
                                    });
        });
    </script>
</head>
<body>
    <div>
        <h2>Details</h2>
        <fieldset>
            <legend>Company</legend>
            <input type="hidden" id="CompanyId" value="@Model.ID" />
            <div class="field">
                <div class="display-label" id="lblName">Name</div>
                <div class="display-field text" id="Name">@Model.Name</div>
            </div>

            <div class="field">
                <div class="display-label" id="lblAddress">Address</div>
                <div class="display-field textarea" id="Address">@Model.Address</div>
            </div>
            <div class="field">
                <div class="display-label" id="lblTown">Town</div>
                <div class="display-field select" id="Country">@Model.Town</div>
            </div>
        </fieldset>
    </div>
</body>
</html>

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
Program Manager Microsoft
Serbia Serbia
Graduated from Faculty of Electrical Engineering, Department of Computer Techniques and Informatics, University of Belgrade, Serbia.
Currently working in Microsoft as Program Manager on SQL Server product.
Member of JQuery community - created few popular plugins (four popular JQuery DataTables add-ins and loadJSON template engine).
Interests: Web and databases, Software engineering process(estimation and standardization), mobile and business intelligence platforms.

Comments and Discussions