【发布时间】:2017-08-17 09:53:41
【问题描述】:
我正在尝试从控制器调用 ViewComponent 并通过以下方式将一些参数作为匿名对象传递:
public IActionResult Test(string pod, string start, string end)
{
ServiceClient r2s = new R2S.ServiceClient();
R2S.Konstant[] kData = r2s.GetKonstantListAsync(new string[] { "STATION" }, new string[] { pod }).Result; // mätarnummer in... --> alla konstanter kopplade till denna.
return ViewComponent("MeterReader2", new { k = kData[0], fromDate = start, toDate = end });
}
我的 ViewComponent 看起来像这样:
public class MeterReader2ViewComponent : ViewComponent
{
public async Task<IViewComponentResult> InvokeAsync(Models.Konstant k, string fromDate, string toDate) // Endast en kanal.
{
code....
}
}
我在 ViewComponent 中放置了一个断点。当我运行代码时,它不会中断。但是,如果我只是调用 ViewComponent 而不传递任何值,它确实会中断。像这样:
public IActionResult Test(string pod, string start, string end)
{
ServiceClient r2s = new R2S.ServiceClient();
R2S.Konstant[] kData = r2s.GetKonstantListAsync(new string[] { "STATION" }, new string[] { pod }).Result; // mätarnummer in... --> alla konstanter kopplade till denna.
return ViewComponent("MeterReader2");
}
【问题讨论】:
标签: c# asp.net-core asp.net-core-viewcomponent