MVCxDashboardViewer Class
Namespace: DevExpress.DashboardWeb.Mvc
Assembly: DevExpress.Dashboard.v18.2.Web.Mvc5.dll
Declaration
public class MVCxDashboardViewer :
ASPxDashboardViewer
Public Class MVCxDashboardViewer
Inherits ASPxDashboardViewer
Important
This documentation applies to v16.2. Starting with v17.1, the ASPxDashboardViewer control is in maintenance mode. In v19.1, the new Web Dashboard Control replaces the old Web Dashboard Viewer. This means that the Web Dashboard Viewer will not be included in our installation packages. See our blog post for more information.
Refer to the following KB articles to learn how to migrate to ASPxDashboard / ASP.NET MVC Dashboard:
The MVCxDashboardViewer class renders the DashboardViewerExtension in ASP.NET MVC applications.
In most scenarios, it is not required to use the MVCxDashboardViewer class in the production code.
To properly follow the ASP.NET MVC pattern when implementing a Dashboard Viewer, use the DashboardViewerExtension and DashboardViewerSettings classes.
The MVCxClientDashboardViewer class is the client-side counterpart of the MVCxDashboardViewer control.
To learn about using these classes, refer to Integration of the DashboardViewer Extension into the Project.
Example
The following example demonstrates how to load a dashboard to an MVC Dashboard Viewer at runtime.
@using(Html.BeginForm()) {
@Html.Action("DashboardViewerPartial")
}
@model DevExpress.DashboardWeb.Mvc.DashboardSourceModel
@Html.DevExpress().DashboardViewer(settings => {
settings.Name = "DashboardViewer";
settings.CallbackRouteValues = new { Controller = "Home", Action = "DashboardViewerPartial" };
settings.ExportRouteValues = new { Controller = "Home", Action = "DashboardViewerPartialExport" };
settings.FullscreenMode = true;
}).BindToSource(Model).GetHtml()
Imports System.Web.Mvc
Imports DevExpress.DashboardWeb.Mvc
Imports DevExpress.DataAccess.ConnectionParameters
Imports System.IO
Namespace MVCLoadingDashboard.Controllers
Public Class HomeController
Inherits Controller
Public Function Index() As ActionResult
Return View()
End Function
<ValidateInput(False)> _
Public Function DashboardViewerPartial() As ActionResult
Return PartialView("_DashboardViewerPartial", DashboardViewerSettings.Model)
End Function
Public Function DashboardViewerPartialExport() As FileStreamResult
Return DashboardViewerExtension.Export("DashboardViewer", DashboardViewerSettings.Model)
End Function
End Class
Friend Class DashboardViewerSettings
Public Shared ReadOnly Property Model() As DashboardSourceModel
Get
Dim model_Renamed As New DashboardSourceModel()
model_Renamed.DashboardId = "SalesDashboard"
model_Renamed.DashboardLoading = Sub(sender, e)
' Checks the identifier of the required dashboard.
If e.DashboardId = "SalesDashboard" Then
' Writes the dashboard XML definition from a file to a string.
Dim dashboardDefinition As String =
File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath("~\App_Data\SalesDashboard.xml"))
' Specifies the dashboard XML definition.
e.DashboardXml = dashboardDefinition
End If
End Sub
model_Renamed.ConfigureDataConnection = Sub(sender, e)
If e.DataSourceName = "SQL Data Source 1" Then
' Gets connection parameters used to establish a connection to the database.
Dim parameters As Access97ConnectionParameters =
CType(e.ConnectionParameters, Access97ConnectionParameters)
Dim databasePath As String = System.Web.Hosting.HostingEnvironment.MapPath("~\App_Data\nwind.mdb")
' Specifies the path to a database file.
parameters.FileName = databasePath
End If
End Sub
Return model_Renamed
End Get
End Property
End Class
End Namespace
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
@Html.DevExpress().GetStyleSheets(
new StyleSheet { ExtensionSuite = ExtensionSuite.DashboardViewer }
)
@Html.DevExpress().GetScripts(
new Script { ExtensionSuite = ExtensionSuite.DashboardViewer }
)
</head>
<body>
<div class="content">
@RenderBody()
</div>
</body>
</html>
@model DevExpress.DashboardWeb.Mvc.DashboardSourceModel
@Html.DevExpress().DashboardViewer(settings => {
settings.Name = "DashboardViewer";
settings.CallbackRouteValues = new { Controller = "Home", Action = "DashboardViewerPartial" };
settings.ExportRouteValues = new { Controller = "Home", Action = "DashboardViewerPartialExport" };
settings.FullscreenMode = true;
}).BindToSource(Model).GetHtml()
using System.Web.Mvc;
using DevExpress.DashboardWeb.Mvc;
using DevExpress.DataAccess.ConnectionParameters;
using System.IO;
namespace MVCLoadingDashboard.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[ValidateInput(false)]
public ActionResult DashboardViewerPartial() {
return PartialView("_DashboardViewerPartial", DashboardViewerSettings.Model);
}
public FileStreamResult DashboardViewerPartialExport() {
return DashboardViewerExtension.Export("DashboardViewer", DashboardViewerSettings.Model);
}
}
class DashboardViewerSettings {
public static DashboardSourceModel Model {
get {
DashboardSourceModel model = new DashboardSourceModel();
model.DashboardId = "SalesDashboard";
model.DashboardLoading = (sender, e) => {
// Checks the identifier of the required dashboard.
if (e.DashboardId == "SalesDashboard") {
// Writes the dashboard XML definition from a file to a string.
string dashboardDefinition = File.ReadAllText(System.Web.Hosting.
HostingEnvironment.MapPath(@"~\App_Data\SalesDashboard.xml"));
// Specifies the dashboard XML definition.
e.DashboardXml = dashboardDefinition;
}
};
model.ConfigureDataConnection = (sender, e) => {
if (e.DataSourceName == "SQL Data Source 1") {
// Gets connection parameters used to establish a connection to the database.
Access97ConnectionParameters parameters =
(Access97ConnectionParameters)e.ConnectionParameters;
string databasePath = System.Web.Hosting.
HostingEnvironment.MapPath(@"~\App_Data\nwind.mdb");
// Specifies the path to a database file.
parameters.FileName = databasePath;
}
};
return model;
}
}
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
@Html.DevExpress().GetStyleSheets(
new StyleSheet { ExtensionSuite = ExtensionSuite.DashboardViewer }
)
@Html.DevExpress().GetScripts(
new Script { ExtensionSuite = ExtensionSuite.DashboardViewer }
)
</head>
<body>
<div class="content">
@RenderBody()
</div>
</body>
</html>
@using(Html.BeginForm()) {
@Html.Action("DashboardViewerPartial")
}
See Also