简体   繁体   English

重新渲染 Blazor 组件

[英]Re-render Blazor Component

I have a catalogue page that renders a Blazor component which displays a list of products with the following code:我有一个呈现 Blazor 组件的目录页面,该组件显示具有以下代码的产品列表:

@(await Html.RenderComponentAsync<ProductList>(RenderMode.ServerPrerendered, new { MinimumPrice = Model.MinimumPrice, MaximumPrice = Model.MaximumPrice }))

Now, I want to change the values of MinimumPrice and MaximumPrice from the catalogue page and have the blazor component re-rendered after the values have changed.现在,我想从目录页面更改MinimumPriceMaximumPrice的值,并在值更改后重新渲染 blazor 组件。

How can I do that from the catalogue page?我怎样才能从目录页面做到这一点?

Thanks.谢谢。

You want to change the razor view and then update the blazor component?您想更改 razor 视图,然后更新 blazor 组件吗?

You can submit a form to change the Model.MinimumPrice, because you can't change the Model您可以提交表单来更改 Model.MinimumPrice,因为您无法更改 Model

in view, it's from server side , so you should change it in server side too.看来,它来自服务器端,所以你也应该在服务器端更改它。

This is the demo:这是演示:

blazor component: blazor 组件:

<p>Min:@MinimumPrice</p>

@code {
[Parameter]
public int MinimumPrice { get; set; }

[Parameter]
public int MaximumPrice { get; set; }
}

Razor view: Razor 查看:

<form method="post">
Change min to<input type="text" name="value"/>
<input type="submit" value="ok" class="btn btn-primary" />
</form>
<component type="typeof(S42111.Components.ProductList)" render-mode="Static" param-MinimumPrice="Model.MinimumPrice" param-MaximumPrice="10" />

server side:服务器端:

[BindProperty]
    public int MinimumPrice { get; set; }
    public void OnGet()
    {
        MinimumPrice = 1;
    }
    public async Task<IActionResult> OnPostAsync(int value)
    {
        this.MinimumPrice = value;
        return Page();
    }

Result:结果: 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM