简体   繁体   English

绑定 object 到 Blazor 路由

[英]Binding object to the Blazor routing

I want to bind my page URL with an object that represents a request filter(productName, categoryId.etc).我想将我的页面 URL 与代表请求过滤器(productName,categoryId.etc)的 object 绑定。 How can I bind them in blazor with query string?如何使用查询字符串将它们绑定到 blazor 中?

@page "/products/{filter}"... @code {

public Filter filter = new Filter()
{
    SearchedName = "Test",
    CategoryId = 1
};

} }

I want something like that.我想要那样的东西。 In Asp.Net Core I am able to bind an object with form and query string but in blazor I have some trouble.在 Asp.Net Core 中,我可以将 object 与表单和查询字符串绑定,但在 blazor 中我遇到了一些麻烦。 Can you give solution for this.你能为此提供解决方案吗? Thanks in advance!提前致谢!

I believe that currently you can't pass complex content as a Route parameter.我相信目前您不能将复杂的内容作为 Route 参数传递。

Instead you should use Component Attribute Parameter as this code snippet demonstrate:相反,您应该使用组件属性参数,因为此代码片段演示:

In a parent component instantiate a variable of type Filter and assign it to the Filter Attribute Property of the Products component在父组件中实例化一个 Filter 类型的变量并将其分配给 Products 组件的 Filter Attribute Property

<products Fitler = "@AFilterInstance" /> , in which you should define a parameter property that will store the passed value like this: <products Fitler = "@AFilterInstance" /> ,您应该在其中定义一个参数属性,该属性将存储传递的值,如下所示:

[Parameter]
public Filter Filter { get; set; }

Hope this helps...希望这可以帮助...

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

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