CriticalPathTraining / PowerBiEmbedded

Resources and Sample Files associated with Ted Pattison's Power BI Embedded webinar
MIT License
58 stars 50 forks source link

How to display Power BI Reports collection using @Html.PowerBIReport #1

Open jaiswati opened 7 years ago

jaiswati commented 7 years ago

How to display Power BI Reports collection using @Html.PowerBIReport

I tried this, looping through all report collection in view (MVC) ?, but only one report was displayed multiple times (but report collection has multiple distinct reports? is this not supported yest

Swati

TedPattison commented 7 years ago

Look at the sample app here: https://github.com/CriticalPathTraining/PowerBiEmbedded/tree/master/PowerBiEmbeddedReportViewer

Inside PowerBiEmbeddedReportViewer/Controllers, look at HomeController.cs and find this code.

IList reports = client.Reports.GetReportsAsync(workspaceCollection, workspaceId).Result.Value; var viewModel = new ReportsViewModel { Reports = reports.ToList() };

Then if you look in the MVC view file named Index.cshtml, you will see this code which adds all reports to the menu for selecting which report to load.

`@foreach (var report in Model.Reports) { var reportClass = Request.QueryString["reportId"] == report.Id ? "activeReport" : "";

  • @Html.ActionLink(report.Name, "Index", new { reportId = report.Id })
  • }`

    By the time you use the @Html.PowerBIReport tag in an MVC view, you must decide which particualr report you want to view.

    If you want to see this app in action and how it offers the user the ability to load any report in an Azure workspace for Power BI, check out the live version at http://powerbireportviewer.azurewebsites.net/