Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Jqgrid主详图don';不要发送适当的信息_C#_Asp.net Mvc_Jqgrid_Master Detail - Fatal编程技术网

C# Jqgrid主详图don';不要发送适当的信息

C# Jqgrid主详图don';不要发送适当的信息,c#,asp.net-mvc,jqgrid,master-detail,C#,Asp.net Mvc,Jqgrid,Master Detail,我在这里搜索我的问题并找到一些提示,但无论如何都不起作用,我的问题是: 在jqgrid Javascrip中,我将以下内容作为setGridParam发送:{url:'myurl/myfunction/'+id,page:1,datatype:“json”}但是,Jgqgrid仍然没有向我的控制器发送用于选择细节的id,它总是空的。。。。。我什么都试过了,问题依然存在,请帮帮我 以下是我的Javascript: <script type="text/javascript">

我在这里搜索我的问题并找到一些提示,但无论如何都不起作用,我的问题是:

在jqgrid Javascrip中,我将以下内容作为setGridParam发送:
{url:'myurl/myfunction/'+id,page:1,datatype:“json”}
但是,Jgqgrid仍然没有向我的控制器发送用于选择细节的id,它总是空的。。。。。我什么都试过了,问题依然存在,请帮帮我

以下是我的Javascript:

<script type="text/javascript">
    jQuery(document).ready(function() {
        jQuery("#list").jqGrid({
        url: '/Master/GridData/',
            datatype: 'json',
            mtype: 'GET',
            colNames: ['Id', 'Descripción'],
            colModel: [
                        { name: 'Id', index: 'Id', width: 50 },
                        { name: 'Descripcion', index: 'Descripcion', width: 80, sortable: true, editable: true, edittype: "text", editoptions: { maxlength: "100"} }
                      ],
            pager: jQuery('#pager'),

            autowidth: true,
            rowList: [5, 10, 20, 50],
            sortname: 'Id',
            sortorder: "asc",
            viewrecords: true,
            caption: '<b>Listado de Masters</b>',
            onSelectRow: function(ids) {
                if (ids != null) {
                    var data = $("#list").getRowData(ids);
                    jQuery("#DetailList").setGridParam({ url: "/Master/DetailGridData/" + data.Id, page: 1, datatype: 'json' })
           .setCaption("<b>Details of Master : " + data.Descripcion+"</b>")
           .trigger('reloadGrid');
                }
            }
        }).navGrid(pager, { edit: false, add: false, del: false, refresh: true, search: false });
        jQuery("#DetailList").jqGrid
        ({
            height: 100,
            datatype: "json",
            colNames: ['Id', 'Descripción', 'Modelo'],
            colModel: [
                        { name: 'Id', index: 'Id', width: 50 },
                        { name: 'Descripcion', index: 'Descripcion', width: 80, sortable: true, editable: true, edittype: "text", editoptions: { maxlength: "100"} },
                        { name: 'Modelo', index: 'Modelo', width: 80, sortable: true, editable: true, edittype: "text", editoptions: { maxlength: "100"} }                            
                      ],
            rowNum: 5,
            rowList: [5, 10, 20],
            pager: jQuery('#DetailPager'),
            sortname: 'Id',
            viewrecords: true,
            sortorder: "desc"
        }).navGrid('#DetailPager', { add: false, edit: false, del: false, search: false });
    });
</script>

jQuery(文档).ready(函数(){
jQuery(“#list”).jqGrid({
url:“/Master/GridData/”,
数据类型:“json”,
mtype:'获取',
colNames:['Id','Descripción'],
colModel:[
{name:'Id',index:'Id',宽度:50},
{name:'descripion',index:'descripion',宽度:80,可排序:true,可编辑:true,edittype:'text',editoptions:{maxlength:'100}}
],
pager:jQuery(“#pager”),
自动宽度:正确,
行列表:[5,10,20,50],
sortname:'Id',
分拣员:“asc”,
viewrecords:是的,
描述:“马斯特斯之旅”,
OnSetrow:功能(ids){
如果(id!=null){
var数据=$(“#列表”).getRowData(ID);
jQuery(“#DetailList”).setGridParam({url:“/Master/DetailGridData/”+data.Id,第1页,数据类型:'json'})
.setCaption(“主控信息的详细信息:+data.description+”)
.触发器(“重新加载网格”);
}
}
}).navGrid(分页器,{edit:false,add:false,del:false,refresh:true,search:false});
jQuery(“#详细列表”).jqGrid
({
身高:100,
数据类型:“json”,
colNames:['Id','Descripción','Modelo'],
colModel:[
{name:'Id',index:'Id',宽度:50},
{name:'descripion',index:'descripion',宽度:80,可排序:true,可编辑:true,edittype:'text',editoptions:{maxlength:'100},
{name:'Modelo',index:'Modelo',宽度:80,可排序:true,可编辑:true,edittype:'text',editoptions:{maxlength:'100}
],
行数:5,
行列表:[5,10,20],
pager:jQuery(“#DetailPager”),
sortname:'Id',
viewrecords:是的,
排序器:“描述”
}).navGrid(“#DetailPager”,{add:false,edit:false,del:false,search:false});
});
这是我的控制器代码:

    public ActionResult GridData(string sidx, string sord, int? page, int? rows)
    {

        List<Master> ms = new List<Master>();
        ms = MasterRepository.GetAll().ToList<Master>();

        int pageIndex = Convert.ToInt32(page) - 1;
        int totalrecords = ms.Count();
        int totalpages = (int)Math.Ceiling((decimal)totalrecords / (decimal)rows);

        var jsonData = new
        {
            sidx = "Id",
            sord = "asc",
            page = 1,
            records = 25,
            rows = (
                    from ch in ms
                    select new
                    {
                        id = ch.Id,
                        cell = new string[] 
                            {
                                ch.Id.ToString(),
                                ch.Descripcion,
                            }
                    }).ToArray(),

        };

        return Json(jsonData, JsonRequestBehavior.AllowGet);
    }



    public ActionResult DetailGridData(string IdMaster, string sidx, string sord, int? page, int? rows)
    {

        int IdCh = Convert.ToInt32(IdMaster);

        IList<Detail> det = new List<Detail>();
        det = DetailRepository.GetByMaster(IdCh).ToList<Detail>();

        int pageIndex = Convert.ToInt32(page) - 1;
        int totalrecords = det.Count();

        var jsonData = new
        {
            sidx = "Id",
            sord = "asc",
            page = 1,
            records = 25,
            rows = (
                    from bah in det
                    select new
                    {
                        id = bah.Id,
                        cell = new string[] 
                            {
                                bah.Id.ToString(),
                                bah.Descripcion,
                                bah.Modelo                                   
                            }
                    }).ToArray(),
        };
        return Json(jsonData, JsonRequestBehavior.AllowGet);
    }
}
}
public ActionResult GridData(字符串sidx、字符串sord、int-page、int-rows)
{
List ms=新列表();
ms=MasterRepository.GetAll().ToList();
int pageIndex=Convert.ToInt32(第页)-1;
int totalrecords=ms.Count();
int totalpages=(int)数学上限((十进制)totalrecords/(十进制)行);
var jsonData=new
{
sidx=“Id”,
sord=“asc”,
第页=1,
记录=25,
行=(
来自中国微软
选择新的
{
id=通道id,
单元格=新字符串[]
{
ch.Id.ToString(),
总描述,
}
}).ToArray(),
};
返回Json(jsonData、JsonRequestBehavior.AllowGet);
}
public ActionResult DetailGridData(字符串IdMaster、字符串sidx、字符串sord、整型页面、整型行)
{
int IdCh=转换为32(IdMaster);
IList det=新列表();
det=DetailRepository.GetByMaster(IdCh.ToList();
int pageIndex=Convert.ToInt32(第页)-1;
int totalrecords=det.Count();
var jsonData=new
{
sidx=“Id”,
sord=“asc”,
第页=1,
记录=25,
行=(
从bah到det
选择新的
{
id=bah.id,
单元格=新字符串[]
{
bah.Id.ToString(),
呸,描述一下,
呸,莫代洛
}
}).ToArray(),
};
返回Json(jsonData、JsonRequestBehavior.AllowGet);
}
}
}

我认为您应该验证添加到route表中的
routes.MapRoute
。您真的使用了
IdMaster
参数,还是应该将其重命名为
Id
?您可能只是忘记添加自定义规则

我看到的另一个问题是语法错误:您使用

.navGrid(pager, {...
而不是

.navGrid('#pager', {...
(未定义中的变量
pager

另一个可能的问题是可能的id重复。确保详图网格的ID具有另一个值作为主网格的ID。因为Id是字符串,所以您可以为Id使用前缀:例如,主网格使用
'm_u'+ch.Id
,详细网格使用
'd_'+bah.Id

还有一些评论:

  • sidx
    sord
    不应包含在服务器的JSON响应中。而不应包括
    总计
    。有关更多信息,请参阅
  • 我建议您使用
    datatype:“local”
    而不是
    datatype:“json”
    作为详细的网格定义。它将阻止在网格初始化时加载数据的尝试
  • 我建议您使用
    pager:'#pager'
    而不是
    pager:jQuery('#pager')
  • 我建议您在
    'Id'
    列中使用
    键:true
    。这样的话,你就不用担心了
    jQuery("#DetailList").setGridParam({ datatype: 'json', url: "/Master/DetailGridData?IdMaster=" + data.IdMaster, page: 1 })