0

目前我正在尝试将整个对象传递给 CallbackRouteValues body 。我试过这个

@Html.DevExpress.ReportViewer(
    New ReportViewerSettings With {
        .Name = Model.ReportID,
        .Report = Model.Report,
        .CallbackRouteValues = New With {.ReportID = Model.ReportID, .Model = Model, .Controller = "Sales", .Action = "GenerateSalesReceiptPartial"},
        .ExportRouteValues = New With {.Controller = "Sales", .Action = "ExportReportViewerPartial", .ReportID = Model.ReportID},
        .PrintUsingAdobePlugIn = False
    }
).GetHtml()

对于控制器,我尝试了这个

Function GenerateSalesReceiptPartial(Model As ReceiptModels.View) As ActionResult

其中 ReceiptModels.View 是一个类,但模型无法将自身绑定到该类,从而导致空对象。有没有其他方法可以将整个对象传递给回调?

谢谢

4

1 回答 1

0

ReportViewer 使用 CallbackRouteValues 值来创建回调 URL。因此,模型实例将被转换为字符串。

ASP.NET MVC 引擎无法解析字符串并创建类实例,除非它是简单类型。为此,创建一个TypeConverter后代,覆盖其CanConvertFromConvertFrom方法,并实现从 String 类型到模型类型的转换。通过TypeConverterAttribute属性将此转换器分配给模型类。

不过,UrlHelper 类(ReportVirwer 使用它来创建回调 URL)不使用类型转换器。要处理从模型到 String 类型的转换,请在模型类中实现IConvertible接口。

于 2013-06-22T18:08:47.820 回答