我正在尝试在我的 MVC 3 Web 应用程序中使用 DevExpress 报告“此应用程序是普通的 MVC 3 应用程序,而不是 DevExpress MVC 3 应用程序”,使用以下教程添加 XtraReports http://documentation.devexpress.com/#XtraReports/CustomDocument9974
问题是每次我尝试添加
@Html.DevExpress().ReportToolbar(settings => {
// The following settings are necessary for a Report Toolbar.
settings.Name = "ReportToolbar";
settings.ReportViewerName = "reportViewer1";
}).GetHtml()
DevExpress() 给我一个错误
'System.Web.Mvc.HtmlHelper' 不包含 'DevExpress' 的定义并且没有扩展方法 'DevExpress' 接受类型为 'System.Web.Mvc.HtmlHelper' 的第一个参数可以找到(你错过了吗using 指令还是程序集引用?)
有什么建议吗?!
最佳答案
您必须使用此链接中提供的步骤手动将 Devexpress 组件注册到您的项目:
How to: Manually Register DevExpress Extensions to Start Using Them in an MVC Web Application
上面提供的步骤中唯一缺少的是程序集绑定(bind)重定向。没有它,我得到了异常(exception):
[InvalidCastException: Unable to cast object of type 'System.Web.Mvc.HtmlHelper`1[System.Object]' to type 'System.Web.Mvc.HtmlHelper'.]
为防止错误,我将此部分添加到我的主 web.config 中 <configuration>
下:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
这会将旧的 mvc 程序集版本重定向到 MVC 4。对于 MVC 3,bindingRedirect 行应该是这样的:
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
关于asp.net-mvc-3 - Devexpress 在 razor mvc3 中添加报告时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12288625/