在MVC视图中可以编辑X.

时间:2015-01-29 03:24:34

标签: jquery asp.net-mvc x-editable

我试图在html表格中使用X-editable来允许用户编辑和添加评论。我遇到的第一个问题是,尽管对控制器的调用成功更新了对数据库的注释,但x-edit窗口没有关闭,并且jquery错误函数在回调时执行。控制器没有返回错误。

关于如何公开此控件以允许用户添加新记录的任何想法?如果表是空的,我会得到一个链接来启动内联编辑器,但是如果有1个注释我不会。

TIA。

<script type="text/javascript">
$(function() {
    $.fn.editable.defaults.mode = 'inline';
    $('#note').editable({
        url: function(params) {
            params.contactId = document.getElementById('ContactId').value;
            return $.ajax({
                type: 'POST',
                url: '@Url.Action("SaveNote", "Contact")',
                data: JSON.stringify(params),
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                async: true,
                cache: false,
                timeout: 10000,
                success: function(response, newValue) {
                    //$('.className[data-pk="' + $(this).data('pk') + '"]').editable('setValue', newValue);
                },
                error: function(status, msg) {
                    alert(msg);
                }
            });
        },
        // title: 'Enter Note', cols: 2 rows: 8;
    });
});

 <table id="contact-notes-table" border="0" cellpadding="5" cellspacing="0" width="100%"
            class="contact scrollable">
            <thead>
                <tr>
                    <th class="Note">
                        <div>
                            @Html.DisplayNameFor(model => model.FirstOrDefault().Note)
                        </div>
                    </th>
                    <th class="DateCreated">
                        <div>
                            @Html.DisplayNameFor(model => model.FirstOrDefault().DateCreated)
                        </div>
                    </th>
                    <th class="CreatedBy">
                        <div>
                            @Html.DisplayNameFor(model => model.FirstOrDefault().CreatedBy)
                        </div>
                    </th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                    <tr>
                        <td class="Note">
                            <div>
                                <a href="#" id="note" data-original-title title data-type="textarea" data-placeholder="Enter note here..." class="editable editable-click" data-pk=@item.ID>@Html.DisplayFor(modelItem => item.Note)</a>
                            </div>
                        </td>
                        <td class="DateCreated">
                            <div>
                                @Html.DisplayFor(modelItem => item.DateCreated)
                            </div>
                        </td>
                        <td class="CreatedBy">
                            <div>
                                @Html.DisplayFor(modelItem => item.CreatedBy)
                            </div>
                        </td>
                    </tr>
                }
            </tbody>
        </table>

0 个答案:

没有答案
相关问题