我有一个执行Get方法的SurfaceController。当我尝试使用this.CurrentPage访问当前页面时,我收到以下错误
无法在路由值中找到Umbraco路由定义,请求必须在Umbraco请求的上下文中进行
为什么我的控制器无法看到当前页面?
{使用系统;使用System.Threading.Tasks;使用System.Web.Mvc; ...使用Umbraco.Web.Mvc;
public class BenefitStatementPdfSurfaceController : SurfaceController
{
private readonly SelfServiceApiHttpClient _apiClient;
public MySurfaceController(SelfServiceApiHttpClient apiClient)
{
_apiClient = apiClient;
}
[ActionName("MemberPdf")]
[HttpGet]
[Authorize]
public async Task<ActionResult> MemberPdfAsync(int memberNumber, int selectedYear)
{
var content = await _apiClient
.MemberPdfAsync(memberNumber, selectedYear)
.ConfigureAwait(false);
if (content.HasPdf)
{
return this.File(content.Pdf, "application/pdf", $"Statement{selectedYear}_{DateTime.Now:yyyyMMdd}_{DateTime.Now:HHmmss}.pdf");
}
var nodeId = this.CurrentPage.Id; ------ERRORS HERE
...
}
}
}
我认为你需要使用当前的UmbracoContext。
Umbraco有一些你可以使用的辅助方法。
你可以试试下面的代码:
UmbracoHelper helper = new UmbracoHelper(UmbracoContext.Current);
IPublishedContent content = helper.TypedContent(Node.getCurrentNodeId());