【问题标题】:NO URL IS SET - error in jqGrid (Add, Delete dialog)未设置 URL - jqGrid 中的错误(添加、删除对话框)
【发布时间】:2012-03-27 13:01:01
【问题描述】:

我已经关注 Grid 来显示数据,现在当我想添加新记录时,它会给出错误“未设置 URL”

$(document).ready(function () {
        $('#PRGrid').jqGrid({
            //url from wich data should be requested
            url: '@Url.Action("BindData")?FillType=' + getFillType(),
            //event for inline edit
            onSelectRow: function (currentSelectedRow) {
                if (currentSelectedRow && currentSelectedRow != $.lastSelectedRow) {
                    //save changes in row 
                    $('#PRGrid').jqGrid('saveRow', $.lastSelectedRow, false);
                    $.lastSelectedRow = currentSelectedRow;
                }
                //trigger inline edit for row
            },
            //type of data
            datatype: 'json',
            //url access method type
            mtype: 'POST',
            //columns names
            colNames: ['Code', 'Name', 'No_Rooms', 'Dept_Code', 'Total_Items'],
            //columns model
            colModel: [
                        {   name: 'Code', index: 'Code', align: 'left', width: '120px', editable: true, edittype: 'select', editoptions: { maxlength: 25, dataUrl: '@Url.Action("GetRooms")',
                            dataEvents: [{ 
                                type: 'change', fn: function (e) {
                                var ret = $.ajax({
                                url: '@Url.Action("selectRoom")?id=' + $(this).val(),
                                async: false,
                                success: function (ret) {
                                    $('#Name').val(ret.Name);
                                    $('#No_Rooms').val(ret.qty);
                                    $('#Dept_Code').val(ret.DeptCode);
                                    $('#Total_Items').val(ret.Total_Items);}
                                });}
                            }]
                        }},
                        { name: 'Name', index: 'Name', align: 'left', formatter: "text", width: '185px', editable: true, editrules: { required: true }, editoptions: { readonly: 'readonly'} },
                        { name: 'No_Rooms', index: 'No_Rooms', align: 'left', formatter: "text", width: '102px', integer: true, editable: true, editrules: { required: true }, editoptions: { readonly: 'readonly'} },
                        { name: 'Dept_Code', index: 'Dept_Code', align: 'left', formatter: "text", width: '78px', editable: true, editrules: { required: true }, editoptions: { readonly: 'readonly'} },
                        { name: 'Total_Items', index: 'Total_Items', align: 'left', formatter: "text", width: '82px', integer: true, editable: true, editrules: { required: true }, editoptions: { readonly: 'readonly'} },
                    ],
            //pager for grid            
            pager: $('#PRGridPager'),
            //number of rows per page
            rowNum: 5,
            //initial sorting column
            sortname: 'Code',
            //initial sorting direction
            sortorder: 'asc',
            recreateForm:true,
            //we want to display total records count
            viewrecords: true,
            //grid height
            height: '100%'
        });

        $('#PRGrid').jqGrid('navGrid', '#PRGridPager',
                { add: true, del: true, edit:false, search: true },
                {width: '330', url:'@Url.Action("InsertPRGridRecord")', closeAfterAdd: true },
                {width: '330', url:'@Url.Action("DeleteGridRecord")'});

        var dialogPosition = $(this).offset();

当我想在网格中添加或删除记录时出现问题,

这里我定义了 InsertPRGridRecord() 和 DeleteGridRecord() 方法,但是在“添加记录”或“删除记录”对话框中提交数据时,它给出了相同的错误“未设置 URL”。

【问题讨论】:

    标签: jqgrid jqgrid-asp.net


    【解决方案1】:

    我认为问题的存在是因为您使用了不正确的navGrid 参数。您当前的代码使用 '@Url.Action("DeleteGridRecord")' 作为“添加”的 URL,使用 '@Url.Action("InsertPRGridRecord")' 作为“编辑”的 URL。 “删除”的 URL 未指定。

    【讨论】:

    • @ITppl:不客气!如果其他人查看您的代码,这样的事情很简单,但是如果一个人搜索原因,可能需要很多时间才能找到原因。 :-)
    猜你喜欢
    • 2012-07-29
    • 2023-04-06
    • 1970-01-01
    • 2014-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多