Getting Started with ASP.NET MVC Application

This section describes how to create an ASP.NET MVC application with an embedded dashboard viewer.

Project Creation

Create a new empty ASP.NET MVC project using Microsoft Visual Studio IDE 2012 or higher. Refer here for more details.

Adding files and references

Add the scripts, styles and refer fonts that are required for the dashboard from the following location to the application project.

%localappdata%\Syncfusion\Dashboard Platform SDK\Getting Started Samples\Common\Html

Include the dashboard file (*.sydx) in the project and set the Build Action and Copy to Output Directory properties to Content and Copy always, respectively.

MVC build action

Adding Dashboard Viewer Assembly References

Right-click the project and add the following assembly references through choosing Add > Reference... as shown below,

Asp.net MVC dll reference

select the “Syncfusion.EJ.DashboardViewer.Mvc” assembly in the dialog shown, which allows you to use any of the Syncfusion Dashboard components within it.

The above mentioned assembly files can be found in the following Dashboard SDK samples location:

%localappdata%\Syncfusion\Dashboard Platform SDK\Getting Started Samples\Common\Precompiled Assemblies

Dll reference

Binding Dashboard Service

To initiate the dashboard service instance you can follow anyone of the below methods

  1. Hosting Dashboard Service in IIS

  2. Hosting Dashboard Service in IIS Express

  3. Hosting Dashboard Service as Windows Service Background Process

  4. Hosting Dashboard Service as Dll

IMPORTANT

Hosting dashboard service at IIS is recommended for the production environment for object management and other memory management features.

Creating Model, View and Controller

Create a model class DashboardViewerController and add the below code within the class.

using System;
    using System.Web.Mvc;
    public class DashboardViewerController : Controller
    {
	  public ActionResult Index()
	  {
		 ViewBag.DashboardPath = AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "\\\\") + "bin\\\\WorldWideCarSalesDashboard.sydx"; // Or use the remote (online) Dashboard Path. For example, https://dashboardsdk.syncfusion.com//Dashboards//WorldWideCarSalesDashboard.sydx
		 ViewBag.ServiceUrl = "http://localhost:3002/DashboardService.svc"; // Or use the remote (online) Dashboard Service. For example, https://dashboardsdk.syncfusion.com/DashboardService/DashboardService.svc;
		 return View();
	  }
	}
Imports System
    Imports System.Web.Mvc
    Public Class DashboardViewerController
	Inherits Controller
	Public Function Index() As ActionResult
		ViewBag.DashboardPath = AppDomain.CurrentDomain.BaseDirectory.Replace("\", "\\") & "bin\\WorldWideCarSalesDashboard.sydx" '// Or use the remote (online) Dashboard Path. For example, https://dashboardsdk.syncfusion.com//Dashboards//WorldWideCarSalesDashboard.sydx
		ViewBag.ServiceUrl = "http://localhost:3002/DashboardService.svc"; '// Or use the remote (online) Dashboard Service. For example, https://dashboardsdk.syncfusion.com/DashboardService/DashboardService.svc;
	  Return View()
	 End Function
     End Class

NOTE

Make sure the given dashboard path should be accessible with the given Dashboard Service URL.
Provided online Dashboard Service URL above, only for demo purpose.

Add a Razor view (Index.cshtml file) with the following template included.

  • aspx-cs
  • <!DOCTYPE html>
        <html>
        <head>
        <title>Getting Started</title>
        <link href="@Url.Content("~/themes/default-theme/ej.dashboardViewer.all.min.css")" rel="stylesheet">
        <script src="@Url.Content("~/scripts/jquery-1.10.2.min.js")"></script>
        <script src="@Url.Content("~/scripts/jquery.easing.1.3.min.js")"></script>
        <script src="@Url.Content("~/scripts/ej.dashboardViewer.all.min.js")"></script>
        <script src="@Url.Content("~/scripts/ej.unobtrusive.min.js")"></script>
    </head>
    <body>
    </body>
    </html>

    Configuring Web Settings

    In your project’s Web.config file, replace the below assembly information under the system.web section.

  • aspx-cs
  • <httpRuntime targetFramework="4.5" />
        <compilation debug="true" targetFramework="4.5" >
          <assemblies>
            <add assembly="Syncfusion.EJ.DashboardViewer.Mvc"/>
          </assemblies>
        </compilation>
        <pages>
          <namespaces>
            <add namespace="System.Web.Helpers" />
            <add namespace="System.Web.Mvc" />
            <add namespace="System.Web.Mvc.Ajax" />
            <add namespace="System.Web.Mvc.Html" />
            <add namespace="System.Web.Routing" />
            <add namespace="System.Web.WebPages" />
    	  </namespaces>
        </pages>

    Add the below settings under the appSettings section.

  • aspx-cs
  • <add key="UnobtrusiveJavaScriptEnabled" value="true" />

    In your project’s web.config file which is under Views folder, add the below settings under the system.web.webPages.razor section.

  • aspx-cs
  • <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    	<pages pageBaseType="System.Web.Mvc.WebViewPage">
    	   <namespaces>
    	  	  ...
          	  <add namespace="Syncfusion.Dashboard.JavaScript"/>
          	  <add namespace="Syncfusion.Dashboard.MVC.EJ"/>
        	  <add namespace="Syncfusion.Dashboard.JavaScript.Shared"/>
           </namespaces>
    	</pages>

    Control Initialization

    Add the below code under the body section of index.cshtml page to initialize the Dashboard Viewer control.

  • aspx-cs
  • @Html.EJDashboard().DashboardViewer("dashboard").ServiceUrl(@ViewBag.ServiceUrl).DashboardPath(@ViewBag.DashboardPath)

    Configuring Route

    In the RegisterRoutes method in the RouteConfig class in the App_Start folder, set the controller name as DashboardViewer.

    Build and run the application to view the dashboard.

    MVC output

    How to Use the Windows Service as Dashboard Service

    To use the window service as a background process refer,
    Run Windows Dashboard Service as a background process

    Refer the below code snippet to configure the Dashboard Viewer with Windows Dashboard Service:

    Create a model class DashboardViewer and add the below code within the class.

    using System;
        using System.IO;
        using System.Net;
        using Microsoft.Win32;
        public class DashboardViewer
        {
    		private readonly string _environmentFolder = AppDomain.CurrentDomain.BaseDirectory;
    		string Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
    		public string ServiceUrl;
    		public string ErrorMessage;
    		
    		public DashboardViewer()
    		{
    			#region Pick Dashboard Windows Service Url
    			ServiceUrl = GetWindowsServiceUrl();
    			#endregion
    			
    			#region Pick IISExpress or IIS  Dashboard Service Url if Windows Dashboard Service is not running
    			if (ValidateDashboardService(ServiceUrl))
    			{
    				DashboardServiceSerialization serializer = new DashboardServiceSerialization();
    				DashboardServicePreviewSettings settings = new DashboardServicePreviewSettings();
    				string dashboardServiceSettingPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Syncfusion\Dashboard Platform SDK\" + Version + @"\DashboardServiceSetting.xml";
    				if (File.Exists(dashboardServiceSettingPath))
    				{
    					settings = serializer.Deserialize(dashboardServiceSettingPath);
    					if (!ValidateDashboardService(settings.ServiceURL))
    						ServiceUrl = settings.ServiceURL;
    					else
    					{
    						ServiceUrl = string.Empty;
    						ErrorMessage = "Dashboard Service is not running. Run DashboardServiceInstaller.exe file to start Dashboard Service in IIS Express";
    					}
    				}
    				else
    				{
    					ErrorMessage = "Dashboard Service is not running. Run DashboardServiceInstaller.exe file to start Dashboard Service in IIS Express";
    					ServiceUrl = string.Empty;
    				}
    			}
    			#endregion
    		}
    		
    		/// <summary>
    		/// Validate whether Dashboard Service is running in the provided Url
    		/// </summary>
    		/// <param name="dashboardServiceUrl">Dashboard Service Url</param>
    		/// <returns>true, if valid; false otherwise</returns>
    		private static bool ValidateDashboardService(string dashboardServiceUrl)
    		{
    			bool errorOccurred = false;
    			try
    			{
    				if (string.IsNullOrWhiteSpace(dashboardServiceUrl))
    				{
    					return true;
    				}
    				if (!dashboardServiceUrl.Contains("http://") && !dashboardServiceUrl.Contains("https://"))
    					dashboardServiceUrl = "http://" + dashboardServiceUrl + @"/IsServiceExists";
    				else
    					dashboardServiceUrl = dashboardServiceUrl + @"/IsServiceExists";
    				WebRequest request = WebRequest.Create(new Uri(dashboardServiceUrl, UriKind.Absolute));
    				request.Method = "GET";
    				using (WebResponse response = request.GetResponse())
    				{
    					using (StreamReader reader = new StreamReader(response.GetResponseStream()))
    					{
    						string text = reader.ReadToEnd();
    						if (!text.Contains(System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("DashboardServiceExists"))))
    						{
    							errorOccurred = true;
    						}
    					}
    				}
    				dashboardServiceUrl = dashboardServiceUrl.Replace(@"/IsServiceExists", "");
    
    			}
    			catch (Exception e)
    			{
    				dashboardServiceUrl = dashboardServiceUrl.Replace(@"/IsServiceExists", "");
    				errorOccurred = true;
    			}
    			return errorOccurred;
    		}
    		
    		/// <summary>
    		/// Gets the Dashboard Windows Service URL 
    		/// </summary>
    		/// <returns>Service URL of Dashboard Windows Service</returns>
    		private string GetWindowsServiceUrl()
            {
                string url = string.Empty;
                try
                {
                    RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\SyncfusionDashboard\Syncfusion Dashboard Service");
                    if (key == null)
                        key = Registry.LocalMachine.OpenSubKey(@"Software\Wow6432Node\SyncfusionDashboard\Syncfusion Dashboard Service");
                    if (key != null)
                    {
                        url = (string)key.GetValue("ServiceURL");
                        key.Close();
                    }
                }
                catch (Exception)
                {
    
                }
                return url;
            }
           }
    Imports System
        Imports System.IO
        Imports System.Net
        Imports Microsoft.Win32
        Public Class DashboardViewer
    		Private ReadOnly _environmentFolder As String = AppDomain.CurrentDomain.BaseDirectory
    		Private Version As String = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
    		Public ServiceUrl As String
    		Public ErrorMessage As String
    		Public Sub New()
                'Pick Dashboard Windows Service Url
    			ServiceUrl = GetWindowsServiceUrl()
            
                'Pick IISExpress or IIS  Dashboard Service Url if Windows Dashboard Service is not running
    			If ValidateDashboardService(ServiceUrl) Then
    				Dim serializer As New DashboardServiceSerialization()
    				Dim settings As New DashboardServicePreviewSettings()
    				Dim dashboardServiceSettingPath As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\Syncfusion\Dashboard Platform SDK\" & Version & "\DashboardServiceSetting.xml"
    				If File.Exists(dashboardServiceSettingPath) Then
    					settings = serializer.Deserialize(dashboardServiceSettingPath)
    					If Not ValidateDashboardService(settings.ServiceURL) Then
    						ServiceUrl = settings.ServiceURL
    					Else
    						ServiceUrl = String.Empty
    						ErrorMessage = "Dashboard Service is not running. Run DashboardServiceInstaller.exe file to start Dashboard Service in IIS Express"
    					End If
    				Else
    					ErrorMessage = "Dashboard Service is not running. Run DashboardServiceInstaller.exe file to start Dashboard Service in IIS Express"
    					ServiceUrl = String.Empty
    				End If
    			End If
    
    		End Sub
    		
    		''' <summary>
    		''' Validate whether Dashboard Service is running in the Url
    		''' </summary>
    		''' <param name="dashboardServiceUrl">Dashboard Service Url</param>
    		''' <returns>true, if valid; false otherwise</returns>
    		Private Shared Function ValidateDashboardService(ByVal dashboardServiceUrl As String) As Boolean
    			Dim errorOccurred As Boolean = False
    			Try
    				If String.IsNullOrWhiteSpace(dashboardServiceUrl) Then
    					Return True
    				End If
    				If Not dashboardServiceUrl.Contains("http://") AndAlso Not dashboardServiceUrl.Contains("https://") Then
    					dashboardServiceUrl = "http://" & dashboardServiceUrl & "/IsServiceExists"
    				Else
    					dashboardServiceUrl = dashboardServiceUrl & "/IsServiceExists"
    				End If
    				Dim request As WebRequest = WebRequest.Create(New Uri(dashboardServiceUrl, UriKind.Absolute))
    				request.Method = "GET"
    				Using response As WebResponse = request.GetResponse()
    					Using reader As New StreamReader(response.GetResponseStream())
    						Dim text As String = reader.ReadToEnd()
    						If Not text.Contains(System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("DashboardServiceExists"))) Then
    							errorOccurred = True
    						End If
    					End Using
    				End Using
    				dashboardServiceUrl = dashboardServiceUrl.Replace("/IsServiceExists", "")
    
    			Catch e As Exception
    				dashboardServiceUrl = dashboardServiceUrl.Replace("/IsServiceExists", "")
    				errorOccurred = True
    			End Try
    			Return errorOccurred
    		End Function
    		
    		''' <summary>
    		''' Used to pick the Dashboard Windows Service URL 
    		''' </summary>
    		''' <returns>Service URL of Dashboard Windows Service</returns>
    		Private Function GetWindowsServiceUrl() As String
    			Dim url As String = String.Empty
    			Try
    				Dim key As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\SyncfusionDashboard\Syncfusion Dashboard Service")
    				If key Is Nothing Then
    					key = Registry.LocalMachine.OpenSubKey("Software\Wow6432Node\SyncfusionDashboard\Syncfusion Dashboard Service")
    				End If
    				If key IsNot Nothing Then
    					url = CStr(key.GetValue("ServiceURL"))
    					key.Close()
    				End If
    			Catch e1 As Exception
    
    			End Try
    			Return url
        End Function
    	End Class
        End Namespace

    Add a class DashboardServicePreviewSettings and add the below code within the class.

    using System;
        using System.Collections.Generic;
        public class DashboardServicePreviewSettings
        {
    		public string ServiceURL { get; set; }
    		public List<Guid> DashboardServiceInstances { get; set; }
    		public DashboardServicePreviewSettings()
    		{
    			DashboardServiceInstances = new List<Guid>();
    		}
        }
    Imports System
        Imports System.Collections.Generic
        Public Class DashboardServicePreviewSettings
    		Public Property ServiceURL() As String
    		Public Property DashboardServiceInstances() As List(Of Guid)
    		Public Sub New()
    			DashboardServiceInstances = New List(Of Guid)()
    		End Sub
        End Class
    Add a model class `DashboardServiceSerialization` and add the below code within the class to serialize and deserialize the DashboardService URL when Dashboard Service is running in IIS Express.
    
    using System;
        using System.IO;
        using System.Xml.Serialization;
        public class DashboardServiceSerialization
        {
    		static readonly XmlSerializer previewSerializer = new XmlSerializer(typeof(DashboardServicePreviewSettings));
    		public void Serialize(DashboardServicePreviewSettings settings, string path)
    		{
    			try
    			{
    				using (StreamWriter writer = new StreamWriter(path))
    				{
    					previewSerializer.Serialize(writer, settings);
    				}
    			}
    			catch (Exception)
    			{
    
    			}
    		}
    		public DashboardServicePreviewSettings Deserialize(string path)
    		{
    			DashboardServicePreviewSettings settings = new DashboardServicePreviewSettings();
    			try
    			{
    				using (StreamReader reader = new StreamReader(path))
    				{
    					settings = (DashboardServicePreviewSettings)previewSerializer.Deserialize(reader);
    				}
    			}
    			catch (Exception)
    			{
    
    			}
    			return settings;
    		}
    	}
    Imports System
        Imports System.IO
        Imports System.Xml.Serialization
    	Public Class DashboardServiceSerialization
    		Private Shared ReadOnly previewSerializer As New XmlSerializer(GetType(DashboardServicePreviewSettings))
    		Public Sub Serialize(ByVal settings As DashboardServicePreviewSettings, ByVal path As String)
    			Try
    				Using writer As New StreamWriter(path)
    					previewSerializer.Serialize(writer, settings)
    				End Using
    			Catch e1 As Exception
    
    			End Try
    
    		End Sub
    		Public Function Deserialize(ByVal path As String) As DashboardServicePreviewSettings
    			Dim settings As New DashboardServicePreviewSettings()
    			Try
    				Using reader As New StreamReader(path)
    					settings = CType(previewSerializer.Deserialize(reader), DashboardServicePreviewSettings)
    				End Using
    			Catch e1 As Exception
    
    			End Try
    			Return settings
    		End Function
        End Class

    How to embed dashboard service as dll

    To host Syncfusion Dashboard Service as dll, refer the below steps to configure the Dashboard Viewer with Embedded Dashboard Service.

    1. Add the following references from the Service -> bin folder (Syncfusion\Dashboard Platform SDK\Service) of Dashboard Platform SDK sample installed location to your application references.

      • Syncfusion.Dashboard.Base
      • Syncfusion.Dashboard.Compression.Base
      • Syncfusion.Dashboard.Encryption
      • Syncfusion.Dashboard.Json.Base
      • Syncfusion.Dashboard.Serialization
      • Syncfusion.Dashboard.Thrift
      • Syncfusion.Dashboard.ThriftHive.Base
      • Syncfusion.Dashboard.XlsIO.Base
      • Syncfusion.DashboardDesigner.Security
      • Syncfusion.DashboardService.Base
      • Syncfusion.DashboardService
      • Newtonsoft.json (10.0.3)
      • Microsoft.Data.Edm
      • Microsoft.Data.OData
      • Microsoft.WindowsAzure.Storage
      • Microsoft.WindowsAzure.StorageClient
      • Microsoft.AnalysisServices.AdomdClient
      • Microsoft.AnalysisServices.Core
      • Microsoft.AnalysisServices
    2. Create a new controller DashboardServiceController in your application and add the following code snippets to it.

    If your project sample was in MVC, use the below code :
    
    	using System.Net.Http;	
    	using System.Web.Mvc;
        using Syncfusion.DashboardService.Base;
    
    	public class DashboardServiceController : Controller
    	{
    		[HttpPost]
    		public ActionResult ProcessRequestForPost(DashboardServiceArguments arguments)
    		{
    				DashboardServiceBase serviceBase = new DashboardServiceBase();
    				return Json(serviceBase.GetServiceResponse(arguments));
    		}
    
    		[HttpGet]
    		public HttpResponseMessage ProcessRequestForGet(string arguments)
    		{
    				DashboardServiceBase serviceBase = new DashboardServiceBase();
    				var stream = serviceBase.GetServiceResponse(arguments);
    				return serviceBase.GetResponseFromStream(stream);
    		}
    
    		[HttpGet]
    		public string IsServiceExists()
    		{
    				DashboardServiceBase serviceBase = new DashboardServiceBase();
    				return serviceBase.IsServiceExists();
    		}
    
    		[HttpGet]
    		public string Version()
    		{
    				DashboardServiceBase serviceBase = new DashboardServiceBase();
    				return serviceBase.Version();
    		}
    	}
    
    	If your project sample was in Web API, use the below code :
    
    	using System.Net.Http;
    	using System.Web.Mvc;
    	using Syncfusion.DashboardService.Base;
    
    	public class DashboardServiceController : ApiController
    	{
    		[Route("api/DashboardService/ProcessRequestForPost")]
    		[HttpPost]
    		public DashboardServiceBase.ServiceResponse ProcessRequestForPost(DashboardServiceArguments arguments)
    		{
    				DashboardServiceBase serviceBase = new DashboardServiceBase();
    				return serviceBase.GetServiceResponse(arguments);
    		}
    
    		[Route("api/DashboardService/ProcessRequestForGet")]
    		[HttpGet]
    		public HttpResponseMessage ProcessRequestForGet(string arguments)
    		{
    				DashboardServiceBase serviceBase = new DashboardServiceBase();
    				var stream = serviceBase.GetServiceResponse(arguments);
    				return serviceBase.GetResponseFromStream(stream);
    		}
    
    		[Route("api/DashboardService/IsServiceExists")]
    		[HttpGet]
    		public string IsServiceExists()
    		{
    				DashboardServiceBase serviceBase = new DashboardServiceBase();
    				return serviceBase.IsServiceExists();
    		}
    
    		[Route("api/DashboardService/Version")]
    		[HttpGet]
    		public string Version()
    		{
    				DashboardServiceBase serviceBase = new DashboardServiceBase();
    				return serviceBase.Version();
    		}
    	}
    If your project sample was in MVC, use the below code :
    
    	Imports Syncfusion.DashboardService.Base
    	Imports System.Net.Http
    
    	Namespace EmbeddingDashboardServiceAsDLL.Controllers
    
    		Public Class DashboardServiceController Inherits Controller
    			<HttpPost>
    			Public Function ProcessRequestForPost(ByVal arguments As DashboardServiceArguments) As ActionResult
    				Dim serviceBase As New DashboardServiceBase()
    				Return Json(serviceBase.GetServiceResponse(arguments))
    			End Function
    
    			<HttpGet>
    			Public Function ProcessRequestForGet(ByVal arguments As String) As HttpResponseMessage
    				Dim serviceBase As New DashboardServiceBase()
    				Dim stream = serviceBase.GetServiceResponse(arguments)
    				Return serviceBase.GetResponseFromStream(stream)
    			End Function
    
    			<HttpGet>
    			Public Function IsServiceExists() As String
    				Dim serviceBase As New DashboardServiceBase()
    				Return serviceBase.IsServiceExists()
    			End Function
    
    			<HttpGet>
    			Public Function Version() As String
    				Dim serviceBase As New DashboardServiceBase()
    				Return serviceBase.Version()
    			End Function
    		End Class		
    	End Namespace
    	
    
    	If your project sample was in Web API, use the below code :
    	
    	Imports System.Net.Http
    	Imports System.Web.Mvc
    	Imports Syncfusion.DashboardService.Base
    
    	Namespace EmbeddingDashboardServiceAsDLL.Controllers
    
    		Public Class DashboardServiceController Inherits ApiController
    
    			<Route("api/DashboardService/ProcessRequestForPost")>
    			<HttpPost>
    			Public Function ProcessRequestForPost(ByVal arguments As DashboardServiceArguments) As DashboardServiceBase.ServiceResponse
    				Dim serviceBase As DashboardServiceBase = New DashboardServiceBase()
    				Return serviceBase.GetServiceResponse(arguments)
    			End Function
    
    			<Route("api/DashboardService/ProcessRequestForGet")>
    			<HttpGet>
    			Public Function ProcessRequestForGet(ByVal arguments As String) As HttpResponseMessage
    				Dim serviceBase As DashboardServiceBase = New DashboardServiceBase()
    				Dim stream = serviceBase.GetServiceResponse(arguments)
    				Return serviceBase.GetResponseFromStream(stream)
    			End Function
    
    			<Route("api/DashboardService/IsServiceExists")>
    			<HttpGet>
    			Public Function IsServiceExists() As String
    				Dim serviceBase As DashboardServiceBase = New DashboardServiceBase()
    				Return serviceBase.IsServiceExists()
    			End Function
    
    			<Route("api/DashboardService/Version")>
    			<HttpGet>
    			Public Function Version() As String
    				Dim serviceBase As DashboardServiceBase = New DashboardServiceBase()
    				Return serviceBase.Version()
    			End Function
    		End Class
    	End Namespace
    1. Change the ServiceUrl defined in the ‘DashboardViewerController’ as in the below code snippet
    If your project sample was in MVC, use the below code :
    
    	public class DashboardViewerController : Controller
    	{
    		public ActionResult Index()
    		{
    			ViewBag.DashboardPath = AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "\\\\") + "bin\\\\Northwind Traders Sales Analysis.sydx";
    			##ViewBag.ServiceUrl = new UriBuilder(HttpContext.Request.Url.Scheme, HttpContext.Request.Url.Host,                 HttpContext.Request.Url.Port).ToString().TrimEnd('/') + ("/DashboardService");
    			return View();
    		}
    		public ActionResult Dashboard()
    		{
    			ViewBag.DashboardPath = AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "\\\\") + "bin\\\\Northwind Traders Sales Analysis.sydx";
    			ViewBag.ServiceUrl = new UriBuilder(HttpContext.Request.Url.Scheme, HttpContext.Request.Url.Host, HttpContext.Request.Url.Port).ToString().TrimEnd('/') + ("/DashboardService");
    			return View();
    		}
    
    	}
    
    	If your project sample was in Web API, use the below code : 
    
    	public class DashboardViewerController : Controller
    	{
    		public ActionResult Index()
    		{
    			ViewBag.DashboardPath = AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "\\\\") + "bin\\\\Northwind Traders Sales Analysis.sydx";
    			ViewBag.ServiceUrl = Request.Url.AbsoluteUri + ("api/DashboardService");
    			return View();
    		}
    		public ActionResult Dashboard()
    		{
    			ViewBag.DashboardPath = AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "\\\\") + "bin\\\\Northwind Traders Sales Analysis.sydx";
    			ViewBag.ServiceUrl = Request.Url.AbsoluteUri + ("api/DashboardService");
    			return View();
    		}
    
    	}
    If your project sample was in MVC, use the below code :
    
    	Public Class DashboardViewerController Inherits Controller
    
    		Public Function Index() As ActionResult
    			ViewBag.DashboardPath = AppDomain.CurrentDomain.BaseDirectory.Replace("\", "\\") & "bin\\Northwind Traders Sales Analysis.sydx"
    			Return View()
    		End Function
    
    		Public Function Dashboard() As ActionResult
    			ViewBag.DashboardPath = AppDomain.CurrentDomain.BaseDirectory.Replace("\", "\\") & "bin\\Northwind Traders Sales Analysis.sydx"
    			ViewBag.ServiceUrl = New UriBuilder(HttpContext.Request.Url.Scheme, HttpContext.Request.Url.Host, HttpContext.Request.Url.Port).ToString().TrimEnd("/"c) & ("/DashboardService")
    			Return View()
    		End Function
    	End Class
    
    	If your project sample was in Web API, use the below code :
    
    	Public Class DashboardViewerController Inherits Controller
    
    		Public Function Index() As ActionResult
    			ViewBag.DashboardPath = AppDomain.CurrentDomain.BaseDirectory.Replace("\", "\\") & "bin\\Northwind Traders Sales Analysis.sydx"
    			ViewBag.ServiceUrl = Request.Url.AbsoluteUri & ("api/DashboardService")
    			Return View()
    		End Function
    
    		Public Function Dashboard() As ActionResult
    			ViewBag.DashboardPath = AppDomain.CurrentDomain.BaseDirectory.Replace("\", "\\") & "bin\\Northwind Traders Sales Analysis.sydx"
    			ViewBag.ServiceUrl = Request.Url.AbsoluteUri & ("api/DashboardService")
    			Return View()
    		End Function
    	End Class
    1. Add the highlighted code snippet in the Web.config of your sample, if its an MVC application. Add the System.Runtime assembly version according to the System.Object dll version of your MVC application framework.

      Add System.Runtime assembly reference