After sending using [RelayCommand] in maui the setter in ViewModel receives truncated string in Maui

257 views Asked by At

After sending using [RelayCommand] in maui the setter in ViewModel receives truncated string in Maui. Example orginal string: "https://twit.memberfulcontent.com/rss/9039?auth=m9FZurRandomAuthonumbers6yB"

The value of URL is good here:

[RelayCommand]
    async Task Tap(string Url)
    {
        System.Diagnostics.Debug.WriteLine("Tap Sending: " + Url);
        await Shell.Current.GoToAsync($"{nameof(ShowPage)}?Url={Url}");
    }

when recieving here URL is truncated:


namespace NerdNewsNavigator2.ViewModel;

[QueryProperty("Url", "Url")]
public partial class ShowViewModel : ObservableObject
{
    #region Properties
    readonly TwitService _twitService;
    public ObservableCollection<Show> Shows { get; set; } = new();
    public string Url
    {
        set
        { // value is truncated string from Tap above.
            System.Diagnostics.Debug.WriteLine("ShowViewModel Recieving url: " + value);
            _ = GetShows(value);
            OnPropertyChanged(nameof(Shows));
        }
    }
// Code shortened for brevity

Example of passed string: "https://twit.memberfulcontent.com/rss/9039" It gets truncated at ?Auth

Any suggestions on what I may be doing wrong? Or suggestion on a better way to do this? It works fine for string that do not have a ? mark in them. One hundred percent working except on this specific type of string.

I was expecting the string not to be truncated.

1

There are 1 answers

0
H.A.H. On BEST ANSWER

Correct way to pass data between pages in MAUI:

When you navigate:

Dictionary<string, object> query = new()
{
     { nameof(MyModel), myModel }
};
await Shell.Current.GoToAsync($"{nameof(MyPage)}", query);

When you are navigated:

public void ApplyQueryAttributes(IDictionary < string , object > query)
{ 
    myModel = query[nameof(MyModel)] as MyModel;
}

(This solves more than the problem with sanitization)