aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Having issues with NavigateTo

Open msimpsonnz opened this issue 8 years ago • 6 comments

Hi I am having issues with NavigateTo function after submitting a page, it supper simple but cannot seem to make any progress

This is my method I am calling but as soon as the Post message happens it just refreshed the page I was on and doesn't redirect to the new page with the Id, am I doing something wrong? Just updated to Blazor 0.6 and using .NET Core 2.1

        protected async Task SubmitForm()
        {
            var request = await Http.PostJsonAsync<ModeratorResult>("/api/moderator/ScreenText", ci);
            UriHelper.NavigateTo($"/tickets/{request.TrackingId}");

        }

Full code is here https://github.com/msimpsonnz/fn18/tree/master/src/FN18.Blazor.Client

msimpsonnz avatar Oct 01 '18 07:10 msimpsonnz

Perhaps the problem lies here... note the version's value FN18.Blazor.Client.csproj => Version="0.5.1"

enetstudio avatar Oct 01 '18 18:10 enetstudio

Thanks but no, I’ve tried moving back to a simple standalone app but still same issue. I can retrieve data and render the page but upon submission it sends the data and ignores the navigation. Is there an example of this working?

msimpsonnz avatar Oct 01 '18 22:10 msimpsonnz

Try this out, store your route on a string variable and give that to the NavigateTo call. It fix it for me. Also correct me if I'm wrong but I think http call should be inside Using statement, anyway let me know if that fixes you issue

orominioo avatar Oct 04 '18 00:10 orominioo

Thanks, I think it was down to deserialiser throwing an error. I’ve given up with the built in helper for HttpClient and will roll my own

msimpsonnz avatar Oct 07 '18 03:10 msimpsonnz

I ran into the same issue, seems to be related to using await:

` protected void SubmitForm() { var request =Http.PostJsonAsync("/api/moderator/ScreenText", ci); UriHelper.NavigateTo($"/tickets/{request.TrackingId}");

    }

` should do it but of course it's no longer async

jormigo avatar Feb 04 '19 00:02 jormigo

oops, actually: if you're using a button, make sure the type is set to button: <button type="button"

https://github.com/aspnet/Blazor/issues/1731

jormigo avatar Feb 04 '19 00:02 jormigo