类型' System.String'的参数转换输入.Net MVC C#

时间:2014-08-24 19:46:02

标签: c# jquery asp.net-mvc datatables

我正在尝试使用JQuery发送复杂数据列表。通过分析ModelState在项teste01中得到了错误:

  

从'System.String'类型到'FlexGestor.Controllers.AjaxController + Dados'类型的参数转换失败,因为没有类型转换器可以在这些类型之间进行转换。

我正在使用jQuery插件发送此数据。此外,参数aController可以正常发送

班长:

public class Teste
{
    public int dataid {get;set;}
    public string datapackage { get; set;}
    public int packageid {get;set;}
}

public class Dados
{
    public IEnumerable<Teste> teste01;
}

控制器:

[HandleError]
[AcceptVerbs(HttpVerbs.Get)]
[Authorize]
public JsonResult ListaGenerica(DataTables param, string aController, Dados teste01, bool porID = false, string regra = "", int filtroID = 0, string tipo = "")
{

Jquery的

function Controller()
{
    return "EmpresaCarga";
}

function Dados()
{
    var localproducts = [];

    localproducts.push({
            'dataid' : 1, 
            'datapackage' : 'test', 
            'packageid' : 3
        });

    localproducts.push({
            'dataid' : 2, 
            'datapackage' : 'test 01', 
            'packageid' : 4
        });

    return localproducts;
}

var oTable = $('#listagem').dataTable({
"bServerSide": true,
"sAjaxSource": '@Url.Action("ListaGenerica", "Ajax")',
"fnServerParams": function ( aoData ) {            
    aoData.push( { "name": "filtroID", "value": $("#ClienteID").find('option:selected').val() } );
    aoData.push( { "name": "aController", "value": Controller() } );
    aoData.push( { "name": "teste01", "value": JSON.stringify(Dados()) } );
},
"bProcessing": true,
"sPaginationType": "full_numbers",
"aoColumns": [
        { "mDataProp": "Carga", "sTitle": "Carga" },
        { "mDataProp": "DtCarga", "sTitle": "DtCarga", "mRender": function (data, type, full) { return dtConvFromJSON(data); } },       
        { "mDataProp": "Empresa", "sTitle": "Empresa" },
        { "mData": null, "bSortable": false, "mRender": function (data, type, row) { return '<a class="btn btn-default btn-xs" href="/Produto/Detalhar/' + row.EmpresaCargaID + '" title="Clique para abrir"><span class="glyphicon glyphicon-edit"></span></a>';}}
    ],
});

发布值:

Remote Address:::1:33288
Request URL:http://localhost:33288/Ajax/ListaGenerica?sEcho=3&iColumns=4&sColumns=&iDisplayStart=0&iDisplayLength=10&mDataProp_0=Carga&mDataProp_1=DtCarga&mDataProp_2=Empresa&mDataProp_3=&sSearch=&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&sSearch_1=&bRegex_1=false&bSearchable_1=true&sSearch_2=&bRegex_2=false&bSearchable_2=true&sSearch_3=&bRegex_3=false&bSearchable_3=true&iSortCol_0=0&sSortDir_0=asc&iSortingCols=1&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&filtroID=&aController=EmpresaCarga&teste01=%5B%7B%22dataid%22%3A1%2C%22datapackage%22%3A%22test%22%2C%22packageid%22%3A3%7D%2C%7B%22dataid%22%3A2%2C%22datapackage%22%3A%22test+01%22%2C%22packageid%22%3A4%7D%5D&_=1408909952447
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4,es;q=0.2,pl;q=0.2
Connection:keep-alive
Cookie:ASP.NET_SessionId=zjczwosxk1xryzrf01dp1c5d; .ASPXAUTH=FC441021A3A9FF5484BF693672F4DDA9AD4395E310372995ADBF81A3B9E9B726C7AE162A45B040481E2386D733F0621E4E3497DECF3CA814F4A00E83CB0BDF2F4125727C812324D8BB482C6A89374697682F0D9E40E27ED590A18CFC80C7BF5EF4F7D2BCE24EC17E16519101167401CFAE180BC23585784A69A72F96919B3D8352ED31E6FDC18666183053CD22A4EA06
Host:localhost:33288
Referer:http://localhost:33288/GestaoFlex/EmpresaCargaLista
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36
X-Requested-With:XMLHttpRequest
Query String Parametersview sourceview URL encoded
sEcho:3
iColumns:4
sColumns:
iDisplayStart:0
iDisplayLength:10
mDataProp_0:Carga
mDataProp_1:DtCarga
mDataProp_2:Empresa
mDataProp_3:
sSearch:
bRegex:false
sSearch_0:
bRegex_0:false
bSearchable_0:true
sSearch_1:
bRegex_1:false
bSearchable_1:true
sSearch_2:
bRegex_2:false
bSearchable_2:true
sSearch_3:
bRegex_3:false
bSearchable_3:true
iSortCol_0:0
sSortDir_0:asc
iSortingCols:1
bSortable_0:true
bSortable_1:true
bSortable_2:true
bSortable_3:false
filtroID:
aController:EmpresaCarga
teste01:[{"dataid":1,"datapackage":"test","packageid":3},{"dataid":2,"datapackage":"test 01","packageid":4}]
_:1408909952447
Response Headersview source
Cache-Control:private, s-maxage=0
Connection:Close
Content-Length:1132
Content-Type:application/json; charset=utf-8
Date:Sun, 24 Aug 2014 19:52:33 GMT
Server:ASP.NET Development Server/10.0.0.0
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:4.0

0 个答案:

没有答案