首页 新闻 会员 周边 捐助

jqgrid中如何点后面的操作中的编辑图标,跳到相应主键的编辑页面

0
悬赏园豆:10 [已解决问题] 解决于 2014-12-31 13:34

点击最后一个图标如何通过主键主键跳到相应的修改页面!求大神指教。。。。

问题补充:

<script type="text/javascript">
 var MeetId;
    var view = {
        message: function(text, callback) {
            $.optips.succeed({
                time: 1,
                position: { of: $('#wrapper') },
                content: text,
                close: function() { callback ? callback() : null; }
            });
        }
    },
    Meeting = {
        jqgrid: function() {
            var options = {
                url: '@Url.Content("~/Quality/Meeting/GetList")',
                 cellurl:'@Url.Content("~/Quality/Meeting/ModifyField")', cellsubmit: 'remote', cellEdit: @(ViewBag.Permission["Modify"] ? "true" : "false"),              
                sortname: 'OpDate',pager: $('#idenPage'), multiselect: true,shrinkToFit: false,
                colNames: ['Id', '会议内容', '操作时间','操作'],
                colModel: [
                    { name: 'Id', index: 'Id', hidden: true, key: true },
                    { name: 'Content', index: 'Content', align: 'center', width: 350, formatter: function (cellvalue, options, rowObject) {
                            return '<a href="@Url.Content("~/Quality/Meeting/Browse")?id='+rowObject['Id']+'">'+cellvalue+'</a>';
                        }
                    },
                        
                    { name: 'OpDate', index: 'OpDate', align: 'center', width: 120,editable:true }, 
                    { name: $.jgrid.defaults.cleverjqgridactions, sortable: false, align: 'center',width: 60,
                        formatter: function(cellvalue, options, rowObject) {
                            return '<div class="ui-btn-imgarea">'                         
                            @if (ViewBag.Permission["Delete"])
                            {<text>+'<span title="删除" onclick="Meeting.remove(\'delete\',\'' + rowObject.Id + '\')" class="ui-icon ui-icon-delete" style="cursor:pointer"></span>'</text>}
                            @if (ViewBag.Permission["Modify"])
                            {<text>+'<span title="编辑" onclick="Meeting.redirect(\'modify\',{id:\''+ rowObject.Id +'\'})" class="ui-icon ui-icon-edit" style="cursor:pointer"></span>'</text>}
                           + '</div>';
                        }
                    }],
                     afterEditCell: function(rowid, cellname, value, iRow, iCol){
                    var $this=$(event.srcElement).find('input');
                    WdatePicker({el:$this.attr('id'),dateFmt:'yyyy-MM-dd HH:mm'});
                },                                 
                gridComplete: function(rowid) {
                    Meeting.resize();                  
                }
            };
            $('#idenGrid').jqGrid(options);

            $('#idenGrid').jqGrid('navGrid', '#idenPage', { del: false, add: false, edit: false, search: false, refresh: false, view: false })
            @if (ViewBag.Permission["Create"])
            {<text>
            .navButtonAdd('#idenPage', {
                title: '新增', position: '0', cursor: 'pointer', buttonicon: 'NONE',
                caption: '<input type="button" value="新增" class="ui-btn ui-btn-add" onmouseover="this.className=\'ui-btn ui-btn-add-hover\'" onmouseout="this.className=\'ui-btn ui-btn-add\'" />',
                onClickButton: function () { Meeting.redirect('create'); }
            })
            </text>}
            @if (ViewBag.Permission["Delete"])
            {<text>
            .navButtonAdd('#idenPage', {
                title: '删除', position: '0', cursor: 'pointer', buttonicon: 'NONE',
                caption: '<input type="button" value="删除" class="ui-btn ui-btn-delete" onmouseover="this.className=\'ui-btn ui-btn-delete-hover\'" onmouseout="this.className=\'ui-btn ui-btn-delete\'" />',
                onClickButton: function () { Meeting.remove('delete'); }
            })
            </text>}
           .navButtonAdd('#idenPage', {
                title: '返回', position: '0', cursor: 'pointer', buttonicon: 'NONE',
                caption: '<input type="button" value="返回" class="ui-btn ui-btn-back" onmouseover="this.className=\'ui-btn ui-btn-back-hover\'" onmouseout="this.className=\'ui-btn ui-btn-back\'" />',
                onClickButton: function () { Meeting.goback('back'); }
            })
        },
        resize: function () {
            $('#idenGrid').setGridWidth($(window).width()-2);
        },
        reload: function() {
            var params = { url: '@Url.Content("~/Quality/Meeting/GetList")?keyword=' + $('#keyword').val(), page: 1 };
            $('#idenGrid').jqGrid('setGridParam', params).trigger('reloadGrid');
        },
        remove: function(op,id) {
            var params = typeof(id) == 'string' ? [id] : $('#idenGrid').jqGrid('getGridParam', 'selarrrow');
            if (params.length == 0) return view.message('请选择需要删除的记录。');
            $.post('@Url.Content("~/Quality/Meeting/Delete")', { id: params.join(',') }).done(function(data) {
                if (data.result) {
                    Meeting.reload();
                }
                view.message(data.message);
            });
        },
        goback:function(){
        history.go(-1);
        },   
        redirect: function(act, id){
       
            switch(act){
                case 'create':location = '@Url.Content("~/Quality/Meeting/Modify")';break;
                case 'modify':location = '@Url.Content("~/Quality/Meeting/Modify")?id='+id;break;
            }
        }
    };

    $(function () {
  
         Meeting.jqgrid();
        $(window).on('resize', Meeting.resize);
        $('#search').on('click', Meeting.reload);
       
       
    });

       
</script>

 

这里这样   case 'modify':location = '@Url.Content("~/Quality/Meeting/Modify")?id='+id;break;不成功,id没有传过来。求解

renshen4322的主页 renshen4322 | 初学一级 | 园豆:5
提问于:2014-12-30 17:35
< >
分享
最佳答案
0

那你传的id的啥?这样写代码好难读。建议把@开头的后台代码统一写在js的开头。。。这样混用,严重影响可读性。

收获园豆:10
幻天芒 | 高人七级 |园豆:37207 | 2014-12-31 08:46

jqgrid中 获取选择的行的数据,获得的是[object Object]怎么处理?我要获得具体的主键值,如‘c8476207-c4f8-4be6-a69c-dbe6ad941334’。
我是这样写的。
redirect: function(act,rowid){      
            switch(act){
                case 'create':location = '@Url.Content("~/Quality/Meeting/Modify")';break;
                case 'modify':
                 var params = $("#idenGrid").jqGrid('getRowData',rowid); 
               
                location = '@Url.Content("~/Quality/Meeting/Modify")?id='+params;
                break;
            }
        }
后台在点编辑传过来的是[object Object]。
   /// 修改与新增共用页面
        /// </summary>
        /// <param name="overhaul"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Modify(string id)
        {          
            if (string.IsNullOrEmpty(id))
            {
                var model = new QualityMeeting();
                ViewBag.Caption = "新增";              
                return View(model);
            }
            else
            {              
                var model = IqualityMeetionRepository.Get(id);
                ViewBag.Caption = "修改";
                return View(model);
            }
        }

renshen4322 | 园豆:5 (初学一级) | 2014-12-31 10:01

@renshen4322: 你把rowObject里的属性拿出来就好。你需要用param.xxx 这样的,而不是直接传param

幻天芒 | 园豆:37207 (高人七级) | 2014-12-31 10:23

@幻天芒: 问题已经自己解决了。谢谢你。

自己方法粗心了。1.这里改成这样。

  @if (ViewBag.Permission["Modify"])
                            {<text>+'<span title="编辑" onclick="Meeting.redirect(\'modify\',\''+ rowObject.Id +'\')" class="ui-icon ui-icon-edit" style="cursor:pointer"></span>'</text>}
                           + '</div>';

2.下面这样写就ok

 redirect: function(act,id){  
            switch(act){
                case 'create':location = '@Url.Content("~/Quality/Meeting/Modify")';break;
                case 'modify':location = '@Url.Content("~/Quality/Meeting/Modify")?id='+id;
                break;
            }
        },传Id成功

renshen4322 | 园豆:5 (初学一级) | 2014-12-31 13:33

@renshen4322: 我还是建议里不要js和后台代码混这么多。读代码很难受。

幻天芒 | 园豆:37207 (高人七级) | 2014-12-31 14:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册