.动作c#不工作两个参数

本文关键字:两个 参数 工作 动作 | 更新日期: 2023-09-27 18:18:37

我在下面调用JQuery,它工作得很好,但是porID参数没有正确地发送到控制器。Net不是"porID",而是"amp;porID"。这是Chrome网络看到的…

JQuery

oTable = $('#lista_cbo').dataTable({            
                "bServerSide": true,            
                "sAjaxSource": '@Url.Action("ListaGenerica", "Home", new { aController = "CBO", porID = true } )', 
                "bProcessing": true,
                "oSearch": {"sSearch": "" + id  + ""},
                "sPaginationType": "full_numbers",   
                "aoColumns": [
                            { "mDataProp": "CBOID", "sTitle": "ID", "sWidth": "16px" },
                            { "mDataProp": "Sigla", "sTitle": "Sigla", "sWidth": "64px" },
                            { "mDataProp": "Tipo", "sTitle": "Tipo", "sWidth": "64px" },
                            { "mDataProp": "Descricao", "sTitle": "Descrição" },                        
                            { "mData": null, "bSortable": false, "fnRender": function (o) {return '<a class="icone_16x16_detalhe" href=/CBO/Detalhar/' + o.aData["CBOID"] + '>D</a>';}}                          
                ],
            });
控制器c#

[HandleError]
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult ListaGenerica(DataTables param, string aController, bool porID = false)
{
    var iniciaRegistrosEm = param.iDisplayStart;
    var totalRegistrosPorPagina = param.iDisplayLength;
    var totalColunas = param.iColumns;
    var result = ERP.Helpers.ListagemPadrao.ListaPadrao(
            aController, 
            param.iDisplayStart, 
            param.iDisplayLength,
            Request["mDataProp_" + param.iSortCol_0.ToString()],
            param.sSortDir_0,
            param.sSearch,
            porID
            );
    return Json(new
    {
        sEcho = param.sEcho,
        iDisplayStart = param.iDisplayStart,
        iTotalRecords = result.TotalRegistros,
        iTotalDisplayRecords = result.TotalRegistrosVisualizados, 
        aaData = result.Dados 
    }, JsonRequestBehavior.AllowGet);
}

.动作c#不工作两个参数

Wrap @Url。用@Html操作。生:

@Html.Raw(Url.Action("ListaGenerica", "Home", new { aController = "CBO", porID = true } ))

java脚本可能与'&'符号混淆。

看起来你的代码没有问题,假设一个get请求你的url应该是这样的

Home/ListaGenerica/?acontroller=CBO&porId=true 

这是正确的因为porId是querystring &的一部分在它的名字之前是OK