У меня есть страница бритвы с ядром .Net 8, и я установил режим рендеринга на InteractiveServer,
@rendermode InteractiveServer
Я используюsectionContent с переменной, чтобы привязать значение к интерфейсу,
Первоначально переменная устанавливается как пустая строка,
public string? result { get; set; } = "";
и он обновляется при нажатии кнопки, как показано ниже:
result = $"Search Results for\"{Query}\"";
однако значение не привязывается к представлению.
<SectionContent SectionName = "page-header-subtitle">
@result
</SectionContent>
Может ли кто-нибудь помочь?
Вам придется сделать розетку интерактивной:
<SectionOutlet @rendermode = "InteractiveServer" SectionName = "page-header-subtitle" />
Кстати, где результат в вашем примере кода?
а что такое разделOutlet?
Он работает на моем компьютере. Наверняка у вас где-нибудь есть РазделOutlet? Я поместил это в MainLayout.razor.
См. Learn.microsoft.com/en-us/aspnet/core/blazor/comComponents/…
Чтобы расширить ответ Хенка с интерактивностью, установленной на страницу/компонент.
Что ты делаешь по-другому?
Основной макет:
@using Microsoft.AspNetCore.Components.Sections
@inherits LayoutComponentBase
<div class = "page">
<div class = "sidebar">
<NavMenu />
</div>
<main>
<div class = "top-row px-4">
<a href = "https://learn.microsoft.com/aspnet/core/" target = "_blank">About</a>
</div>
<SectionOutlet @rendermode = "InteractiveServer" SectionName = "page-header-subtitle" />
<article class = "content px-4">
@Body
</article>
</main>
</div>
<div id = "blazor-error-ui">
An unhandled error has occurred.
<a href = "" class = "reload">Reload</a>
<a class = "dismiss">🗙</a>
</div>
Прилавок
@page "/counter"
@using Microsoft.AspNetCore.Components.Sections
@rendermode InteractiveServer
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role = "status">Current count: @currentCount</p>
<button class = "btn btn-primary" @onclick = "IncrementCount">Click me</button>
<SectionContent SectionName = "page-header-subtitle">
<div class = "m-2">
@currentCount
</div>
</SectionContent>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
Нет, это тоже не отобразило результат, я что-то упускаю?