我正在使用嵌入在 Visual Studio 中的 Power BI 构建应用程序。我已在控制器中的报告操作中添加了用户名和角色,该用户名和角色对应于我要嵌入的实际报告中的用户名和角色。我想将用户名作为变量从 index.cshtml 中的文本框中传递给 Report 操作;当这个值被硬编码但我不能将它作为变量传递时,报告会加载和嵌入!
这是控制器中的 ActionResult -
public async Task<ActionResult> Report(string reportId)
{
//This is where I'm trying to get the variable from the textbox
username = Request["centreID"].ToString();
using (var client = this.CreatePowerBIClient())
{
var reportsResponse = await client.Reports.GetReportsAsync(this.workspaceCollection, this.workspaceId);
var report = reportsResponse.Value.FirstOrDefault(r => r.Id == reportId);
IEnumerable<string> roles = new List<string>() { "xxxxxxxx" };
// I can hardcode the username here, and it works, but can't pass in a variable from the html like above
//string username = "xxxxxx";
//username = this.username;
var embedToken = PowerBIToken.CreateReportEmbedToken(this.workspaceCollection, this.workspaceId, report.Id, username, roles);
var viewModel = new ReportViewModel
{
Report = report,
AccessToken = embedToken.Generate(this.accessKey)
};
return View(viewModel);
}
}
在模型中是我放置我的获取和设置的地方
public string username { get; set; }
这是我用过的html;我之前在控制器中使用 void 方法对此进行了测试,它确实将变量传递到控制器中
@using (Html.BeginForm("Report", "Dashboard"))
{
@Html.Label("Enter Centre ID")
@Html.TextBox("centreID")
<input type="submit" value="submit" />
}
</span>
</a>