2017-04-07 151 views

回答

1

您不希望查看,並從查詢字符串本身獲取所需的參數。它可以嚴格使用視圖。

相反,您可以從父母傳遞Id

// Parent's Action Method 
public IActionResult ParentActionMethod(int id) 
{ 
    // You could use strongly typed model 
    ViewBag.Id = 1; 
    return View(); 
}  

// Parent's View 
@await Component.InvokeAsync("Layout", new { Id = ViewBag.Id }) 

// View Component 
public class LayoutViewComponent : ViewComponent 
{ 
    public async Task<IViewComponentResult> InvokeAsync(int id = 10) 
    { 
     return View(); 
    } 
}