@ Url.Action C#没有工作两个参数

时间:2013-06-15 17:28:35

标签: c# jquery

我在下面调用JQuery工作正常,但是porID参数没有正确发送到控制器。净而不是获得“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>';}}                          
                ],
            });

Controller 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);

}

2 个答案:

答案 0 :(得分:2)

用@ Html.Raw包裹@ Url.Action:

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

java脚本可能正在搞乱'&amp;'登录。

答案 1 :(得分:0)

您的代码看起来没有任何问题,并假设获取请求您的网址应该是这样的

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

这是正确的,因为porId是查询字符串的一部分&amp;名称之前是好的