Skip to content

Enhance QueryString in blazor #22388

Closed
Closed
@Thaina

Description

@Thaina

I would like blazor to provide better management and handler for querystring of current page url

[FromQuery] attribute for two way binding

It should allow binding to a field and/or property, so that it would always binded with query string with the same name as the property

@code {
        [FromQuery]
	int size = 0;
        [FromQuery("queryName")]
	int internalName = 0;
        [FromQuery("date","yyyyMMddHHmmss")] // with format?
	DateTimeOffset internalName = DateTimeOffset.Now;
}

NavigationManager

Should provide API for URI manipulation and history

public static Uri WithQuery(this Uri uri,string name,string value)
{
    // anything better with the same result?
    var query = HttpUtility.ParseQueryString(uri.Query);
    query[name] = value;
    return new UriBuilder(uri){ Query = query.ToString() }.Uri;
}

void GetAbsoluteUri(this NavigationManager manager) => manager.ToAbsoluteUri(manager.Uri);

// navigateTo(uri.WithQuery())
void SetQuery(this NavigationManager manager,string name,object value);
void SetQuery(this NavigationManager manager,params (string name,object value)[] values);

string GetQuery(this NavigationManager manager,string name);

/////////

// localhost/?q=0 >>> localhost/?q=1
navManager.SetQuery("q",1);
navManager.SetQuery("q",int.Parse(navManager.GetQuery("q")) + 1);

Underlyingly should just call history.pushState if available

Metadata

Metadata

Assignees

Labels

DoneThis issue has been fixedNeeds: DesignThis issue requires design work before implementating.affected-fewThis issue impacts only small number of customersarea-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-builtin-componentsFeatures related to the built in components we ship or could ship in the futureseverity-majorThis label is used by an internal tool

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions