2016-08-23 4 views
1

저는 Visual Studio에 임베디드 BI를 사용하여 앱을 제작하고 있습니다. 내가 포함하려는 실제 보고서의 사용자 이름과 역할에 해당하는 컨트롤러의 보고서 작업에 사용자 이름과 역할을 추가했습니다. index.cshtml의 텍스트 상자에서 Report 액션으로 사용자 이름을 변수로 전달하려고합니다. 이 값이 하드 코드되면 보고서가로드되고 삽입되지만 변수로 전달할 수 없습니다. 여기 MVC Power BI Embedded를 사용하여 변수를 전달하는 방법은 무엇입니까?

컨트롤러의 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); 
    } 
} 

내가 내 GET을 넣고 여기에

public string username { get; set; } 

내가 사용했던 HTML입니다 설정 한 곳이다; 내가 전에 컨트롤러의 빈 공간 방법으로이 테스트를했는데 그것은

@using (Html.BeginForm("Report", "Dashboard")) 
{ 
    @Html.Label("Enter Centre ID") 
    @Html.TextBox("centreID") 

    <input type="submit" value="submit" /> 
} 
</span> 
</a> 
+0

이 줄의 중단 점'username = Request [ "centreID"]. ToString();'... 값을 얻었습니까? – Hackerman

+0

아니요 ... 컨트롤러의 void 메쏘드를 가리키는 html.beginform 액션이 생기기 전에, 다음에는 중단 점을 넣었고 그 값을 전달하고있었습니다. 이것은 비동기식이기 때문입니까? –

+0

그리고 'reportId' 값은? – Hackerman

답변

0

당신의 방법은 reportId을 기대하고있다 컨트롤러에 변수를 전달 않지만, 당신이 그것을 호출하는 경우, 그 이름을 가진 컨트롤이 없다 . 이제 당신은 당신의 코드는 다음과 같은 방법으로 업데이트해야하는 ViewBag 내부에 이전 단계에서 그 값을 가지고 있다고 가정하자 :

@using (Html.BeginForm("Report", "Dashboard")) 
{ 
    @Html.Label("Enter Centre ID") 
    @Html.TextBox("centreID") 
    <input type="hidden" name="reportId " value="@(ViewBag.reportId ?? "")" /> 
    <input type="submit" value="submit" /> 
} 

및 추천 방법 : 당신이 넣으면

public async Task<ActionResult> Report(string reportId, string centreID) 
{ 
//This is where I'm trying to get the variable from the textbox 
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 
    var embedToken = PowerBIToken.CreateReportEmbedToken(this.workspaceCollection, this.workspaceId, report.Id, centreID, roles); 
    var viewModel = new ReportViewModel 
    { 
     Report = report, 
     AccessToken = embedToken.Generate(this.accessKey) 
    }; 

    return View(viewModel); 
} 
} 
관련 문제