1024programmer Asp.Net Follow up the ReuseTabs of .NET 8 Blazor to support Query property binding

Follow up the ReuseTabs of .NET 8 Blazor to support Query property binding

The ASP.NET team and community continue to devote all their efforts to Blazor in .NET 8, bringing it a lot of new features, especially in terms of server-side rendering (SSR), which solves the slow loading of WASM and the performance of Server to a certain extent. Not ideal and other limitations, but also with the original MVC, Razor Pages framework to complete the unification at the bottom.

AntDesign Blazor, as one of the most popular open source component libraries of Blazor, will naturally continue to follow up. This article mainly introduces the first new feature of .NET 8 applied on AntDesign Blazor – CascadingModelBinder. I use it to implement the Query String property that has not been supported by ReuseTabs since its release in 2021 for two years bound.

ReuseTabs is a component added by AntDesign Blazor in July 2021, and it is currently the only component of Blazor that truly implements routing reuse. It can be used independently in any Blazor project by adding the RouteData cascade value in App.razor (the example in its documentation is used on the official template), and it can actively identify routes and render page components without relying on menu configuration , and keep the state switching of each Tab page from being lost. Unlike the implementation of other component libraries, it can only be used on their designated supporting templates…

Multi-tab page in Ant Design Blazor component library

Its implementation principle is also very simple. It obtains the component type to be displayed and the attribute value of the page component to be bound through the cascaded RouteData value, and then dynamically renders the component. But because the Query string attribute value binding implementation added in .NET 6 uses an internal static method inside RouteView to parse the QueryString and pass it to the page component, ReuseTabs needs to copy all the code to support it. At that time, I felt that such a design was very limited (later I was too lazy).

Until the update of the article ASP.NET Core in .NET 8 Preview 6 published in the .NET official blog some time ago, a feature was mentioned, cascading the query string value to the Blazor component, which means that the Query is no longer allowed String value binding is limited to page components. I think that the function that ReuseTabs has been missing for two years is hopefully filled.

Cascade query string values ​​to Blazor components - .  NET Blog

So there is the content to be introduced today.

In order to find out how the official implementation is implemented, switch the aspnetcore warehouse source code to the .NET 6 Preivew 6 tag, and find the RenderPageWithParameters method in RouteView.cs in the RouteView source code, which is used to render page components.

RouteView

So I traced the history of this file and found that the PR#47716 that supports server-side static rendering of forms has added CascadingModelBinder, so that the submitted FormData can be obtained from the Http request and bound to the model marked with the SupplyParameterFromForm feature in the component superior.

RouteView CascadingModelBinder

Next, in PR #48554, SupplyParameterFromQuery can also be passed through CascadingModelBinder, and then delete the code related to the internal class QueryParameterValueSupplier in RouteView mentioned above.

RouteView delete QueryParameterValueSupplier

This is right between the eyebrows, I immediately copied this code from RouteView to ReuseTabs, PR https://github.com/ant-design-blazor/ant-design-blazor/pull/3377, perfect!

Ant Design Blazor PR 3377

Final result:
ReuseTabs support query string

Besides being happy, I thought that even if I copy it, I can’t copy it unclearly, so I investigated how CascadingModelBinder passes cascading values ​​by the way. To put it simply, Blazor created the CascadingModelBinder component and the CascadingModelBindingProvider provider to abstract and unify the cascading value transfer method. I didn’t expect such a big change behind the plain two-sentence introduction in the official blog. For details, please pay attention to my next article, and I will introduce it separately.

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/follow-up-the-reusetabs-of-net-8-blazor-to-support-query-property-binding/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索