0
我想從一個控制器調用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", 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");
}
我明白了。我只是嘗試了這種方法。如果我創建一個視圖,然後使用新參數調用ViewComponent,則會正確加載一個新的視圖。但是,我目前已經在另一個ViewComponent中。我如何使調用在同一視圖組件視圖內發生? – jazy