# Cube Data Binding using DataEngine

Develop powerful and lightweight web applications using ASP.NET MVC controls. Learn more about the ComponentOne MVC controls in ASP.NET MVC documentation.

## Content



This section describes the steps required to add cube data in the OLAP control using **SSAS** (SQL Server Analysis Services). In the example below, the PivotEngine component binds to a service. In this the **DataEngine** Web Api is supported, the data engine is responsible for data aggregation in this example. The **PivotPanel** control and **PivotGrid** control binds the **PivotEngine**. You can change the view definition in the **PivotPanel** control. The aggregated data will be obtained from the service. Then the **PivotGrid** control displays the aggregated data.

To accomplish this, follow these steps:

### Create an MVC Application using Visual Studio template

Create an ASP.NET MVC Application using Visual Studio template to enable WebAPI configuration.

1.  Select **File | New | Project**.
2.  Under installed templates, select **Visual C# | Web | ASP.NET Web Application (.NET Framework)**.
3.  In the **New ASP.NET Web Application** dialog, select the **MVC** template.
4.  Under "Add folders and core references for", check **Web API**. Click **OK**.<br />For more information about licensing, resource registration, and assembly references, see [Using Visual Studio Template](/componentone/docs/mvc/online-mvc/CreatingaNewProject/UsingVSTemplate).

### Install the DataEngine Web API

Install the DataEngine Web API and C1.WebApi packages from the NuGet server.

1.  Select **MESCIUS** from the **Package source** drop-down, in NuGet Package manager of your application.
2.  Browse for the DataEngine Web API packages, and install them.<br /><br />![](https://cdn.mescius.io/document-site-files/images/2b3ac322-100e-4637-958d-fb40dcda3f44/images/dataenginenuget.png)<br /><br />You will see that the following references are added to your Visual Studio project.

*   `C1.WebApi.dll`
*   `C1.WebApi.DataEngine.dll`
*   `C1.DataEngine.4.dll`
*   `System.Net.Http.Formatting.dll`
*   `System.Web.Http.dll`
*   `System.Web.Http.Owin.dll`
*   `System.Web.Http.WebHost.dll`

### Configure Startup.cs

After adding the required references, you need to configure the `Startup.cs` to fetch the data that is stored on SSAS server.

1.  In **Solution Explorer**, select your target project.
2.  On the **Project** menu, click **New Item** option.
3.  In the **New Item** dialog, select Web and then select **OWIN Startup class** template from the list on right.
4.  In the Startup.cs file, add the following code inside the **Startup** class.
    
    ```csharp
    using C1.DataEngine;
    using Microsoft.Owin;
    using Owin;
    using System.IO;
    using System.Linq;
    using System.Web.Http;
    using OlapSSAS.Models;
    [assembly: OwinStartupAttribute(typeof(OlapSSAS.Startup))]
    namespace OlapSSAS
    {
     public partial class Startup
       {
     private readonly HttpConfiguration config = GlobalConfiguration.Configuration;
     public void Configuration(IAppBuilder app)
       {
     app.UseDataEngineProviders()
     .AddCube("cube", 
     @"Data Source=http://ssrs.componentone.com/OLAP/msmdpump.dll;
    Provider=msolap;Initial Catalog=AdventureWorksDW2012Multidimensional", 
     "Adventure Works");
            }
        }
    }
    ```
    

### Add an OLAP control

Create a Controller and View for OLAP control and follow the below steps to initialize an OLAP control.

**Add a new Controller**

1.  In the **Solution Explorer**, right click the folder **Controllers.**
2.  From the context menu, select **Add | Controller**. The **Add Scaffold** dialog appears.
3.  Complete the following steps in the **Add Scaffold** dialog:
    1.  Select **MVC 5 Controller - Empty** template.
    2.  Set name of the controller (for example: `OlapController`).
    3.  Click **Add**.
4.  Replace the method Index() with the following method. **csharp**
    
    ```csharp
    // GET: SSAS
    public ActionResult Index()
    {
        return View();
    }
    ```
    

**Add a View for the Controller**

1.  From the **Solution Explorer**, expand the folder **Controllers** and double click the `OlapController.`
2.  Place the cursor inside the method `Index()`.
3.  Right click and select **Add View**. The **Add View** dialog appears.
4.  In the **Add View** dialog, verify that the view name is **Index** and View engine is **Razor (CSHTML).**
5.  Click **Add** to add a view is for the controller. Copy the following code and paste it inside **Index.cshtml**.
    
    ```csharp
    @using C1.Web.Mvc.Olap;
    @using C1.Web.Mvc.Grid
    @Html.C1().Styles()
    @Html.C1().Scripts().Basic().Olap()
    @(Html.C1().PivotEngine().Id("ssasEngine")
                .BindService("~/api/dataengine/cube")
                .RowFields(pfcb => pfcb.Items("[Customer].[Country]"))
                .ColumnFields(cfcb => cfcb.Items("[Customer].[Occupation]"))
                .ValueFields(vfcb => vfcb.Items("[Measures].[Customer Count]")))
    ```
    

### Build and Run the Project

1.  Click **Build | Build Solution** to build the project.
2.  Press **F5** to run the project. 
	> type=note
	> Append the folder name and view name to the generated URL (for example: http://localhost:1234/**Olap/Index**) in the address bar of the browser to see the view.
    
    The following image shows how OLAP control appears in the browser after completing the above steps:
    
    ![](https://cdn.mescius.io/document-site-files/images/2b3ac322-100e-4637-958d-fb40dcda3f44/images/olapssas.png)
    

## See Also

[Data Binding](/componentone/docs/mvc/online-mvc/workwithcontrols/Olap/workwitholap/OlapDataBinding)

[Model Binding](/componentone/docs/mvc/online-mvc/workwithcontrols/Olap/workwitholap/OlapDataBinding/ModelBindingOlap)

[Remote Binding](/componentone/docs/mvc/online-mvc/workwithcontrols/Olap/workwitholap/OlapDataBinding/OlapRemoteBinding)

**Configuring App**

[Using Visual Studio Template](/componentone/docs/mvc/online-mvc/CreatingaNewProject/UsingVSTemplate)