Mohamed Salah
Mohamed Salah

Reputation: 975

Devexpress error in adding reports in razor mvc3

I am trying to use DevExpress reports in my MVC 3 web application "This application is a normal MVC 3 application not a DevExpress MVC 3 application" using the following tutorial for adding XtraReports http://documentation.devexpress.com/#XtraReports/CustomDocument9974

The problem is each time i am trying to add

@Html.DevExpress().ReportToolbar(settings => {
// The following settings are necessary for a Report Toolbar. 
settings.Name = "ReportToolbar";
settings.ReportViewerName = "reportViewer1";
}).GetHtml()

DevExpress() gives me an error

'System.Web.Mvc.HtmlHelper' does not contain a definition for 'DevExpress' and no extension method 'DevExpress' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)

any suggestions?!

Upvotes: 3

Views: 4564

Answers (1)

Huseyin Yagli
Huseyin Yagli

Reputation: 10285

You must use the steps provided in this link to manually register Devexpress components to your project:

How to: Manually Register DevExpress Extensions to Start Using Them in an MVC Web Application

The only thing missing in the steps provided above was the assembly binding redirect. Without it, I was getting the exception:

[InvalidCastException: Unable to cast object of type 'System.Web.Mvc.HtmlHelper`1[System.Object]' to type 'System.Web.Mvc.HtmlHelper'.]

To prevent the error, I added this section to my main web.config under <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>

This will redirect older mvc assembly versions to MVC 4. For MVC 3, the bindingRedirect line should be like this:

<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />

Upvotes: 5

Related Questions