@foreach ((Employee, int) result in searchResults)
{
<tr>
<th scope="row">@result.Item1.Forename, @result.Item1.Surname
<i class="bi bi-info-circle" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasRight" aria-controls="offcanvasRight"></i>
<div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasRight" aria-labelledby="offcanvasRightLabel">
<div class="offcanvas-header">
<h5 id="offcanvasRightLabel">@result.Item1.Forename, @result.Item1.Surname</h5>
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<Profile4Search Id = "@result.Item1.Id"/>
</div>
</div>
</th>我想放入用于员工信息的offcanvas,但是Profile4Search组件没有重新呈现,并且总是显示相同的信息。如何在foreach循环中重新渲染组件?
我认为,组件ProfileSearch从参数接收Id并显示每个员工的详细信息(如果用户单击图标),但它只呈现一次,并显示相同员工的详细信息(这里是循环中的第一个员工)。
发布于 2021-07-26 17:04:58
在C#中使用for-each循环时,通常需要将循环变量赋给临时变量。
@foreach ((Employee, int) result in searchResults)
{
var tmp = result.Item1;
<tr>
<th scope="row">@tmp.Forename, @tmp.Surname不容易确定这是这里的原因,因为你的问题不是很清楚什么是/不是-正在呈现的。更多信息:Why is a temporary variable required in foreach to be included in lambda expression?
https://stackoverflow.com/questions/68522371
复制相似问题