在razor mvc3中添加报告时出现Devexpress错误

Moh*_*lah 3 devexpress asp.net-mvc-3

我试图在我的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()
Run Code Online (Sandbox Code Playgroud)

DevExpress()给了我一个错误

'System.Web.Mvc.HtmlHelper'不包含'DevExpress'的定义,并且没有扩展方法'DevExpress'接受类型'System.Web.Mvc.HtmlHelper'的第一个参数可以找到(你是否缺少using指令)或汇编参考?)

有什么建议?!

Hüs*_*ğlı 5

您必须使用此链接中提供的步骤手动将Devexpress组件注册到项目中:

如何:手动注册DevExpress扩展以在MVC Web应用程序中开始使用它们

上面提供的步骤中唯一缺少的是程序集绑定重定向.没有它,我得到了例外:

[InvalidCastException: Unable to cast object of type 'System.Web.Mvc.HtmlHelper`1[System.Object]' to type 'System.Web.Mvc.HtmlHelper'.]
Run Code Online (Sandbox Code Playgroud)

为防止出现此错误,我将此部分添加到我的主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>
Run Code Online (Sandbox Code Playgroud)

这会将旧的mvc程序集版本重定向到MVC 4.对于MVC 3,bindingRedirect行应该是这样的:

<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
Run Code Online (Sandbox Code Playgroud)